npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-routing-test

v0.1.1

Published

A declarative router for Angular applications

Downloads

1

Readme

angular-routing

A declarative router for Angular applications.

Install

Use your package manager of choice to install the package.

npm install angular-routing

OR

yarn add angular-routing

Usage

To register the Router, add the RoutingModule.forRoot() to your AppModule imports.

import { RoutingModule } from 'angular-routing';

@NgModule({
  imports: [
    // ... other imports
    RoutingModule.forRoot()
  ]
})
export class AppModule {}

Or in a feature module

import { RoutingModule } from 'angular-routing';

@NgModule({
  imports: [
    // ... other imports
    RoutingModule
  ]
})
export class FeatureModule {}

After your components are registered, use the Router and Route components to register some routes.

<router>
  <route path="/blog/**">
    <app-blog *routeComponent></app-blog>
  </route>
  <route path="/posts/:postId">
    <app-post *routeComponent></app-post>
  </route>
  <route path="/about">
    <app-about *routeComponent></app-about>
  </route>
  <route path="/" redirectTo="/blog">
  </route>
  <route path="**">
    <app-page-not-found *routeComponent></app-page-not-found>
  </route>
</router>

Navigating with Links

Use the linkTo directive with a full path to register links handled by the router.

<a linkTo="/">Home</a>
<a linkTo="/about">About</a>
<a linkTo="/blog">Blog</a>

Adding classes to active links

To add classes to links that match the current URL path, use the linkActive directive.

<a linkTo="/" linkActive="active">Home</a>
<a linkTo="/about" linkActive="active">About</a>
<a linkTo="/blog" linkActive="active">Blog</a>

Using the Router service

To navigate from a component class, or get global route information, such as the current URL, or hash fragment, inject the Router service.

import { Component } from '@angular/core';
import { Router } from 'angular-routing';

@Component({...})
export class MyComponent {
  constructor(private router: Router) {}

  ngOnInit() {
    this.router.url$.subscribe();
    this.router.hash$.subscribe();
  }

  goHome() {
    this.router.go('/');
  }
}

Using Route Params

To get the route params, inject the RouteParams observable. Provide a type for the shape of the route params object.

import { Component } from '@angular/core';
import { RouteParams } from 'angular-routing';

@Component({...})
export class MyComponent {
  constructor(
    private routeParams$: RouteParams<{ postId: string }>
  ) {}

  ngOnInit() {
    this.routeParams$.subscribe(console.log);
  }
}

Using Query Params

To get the route params, inject the QueryParams observable. Provide a type for the shape of the query params object.

import { Component } from '@angular/core';
import { QueryParams } from 'angular-routing';

@Component({...})
export class MyComponent {
  constructor(
    private queryParams$: QueryParams<{ debug: boolean }>
  ) {}

  ngOnInit() {
    this.queryParams$.subscribe(console.log);
  }
}

Lazy Loading Modules

To lazy load a module, use the load binding on the route component.

import { Component } from '@angular/core';

@Component({
  template: `
    <router>
      <route path="/lazy/**" [load]="modules.lazy">
      </route>
    </router>
  `
})
export class MyComponent {
  modules = {
    lazy: () => import('./lazy/lazy.module').then(m => m.LazyModule)
  }
}

Register a component to register the child routes.

import { NgModule, Component } from '@angular/core';
import { ModuleWithRoute } from 'angular-routing';

@Component({
  template: `
    <router>
      <route path="/">
        <app-lazy *routeComponent></app-lazy>
      </route>
    </router>  
  `
})
export class LazyRouteComponent { }

Implement the ModuleWithRoute interface for the route component to render after the module is loaded.

@NgModule({
  declarations: [
    LazyRouteComponent,
    LazyComponent
  ]
})
export class LazyModule implements ModuleWithRoute {
  routeComponent = LazyRouteComponent;
}

Lazy Loading Components

To lazy load a component, use the load binding on the route component.

import { Component } from '@angular/core';

@Component({
  template: `
    <router>
      <route path="/lazy" [load]="components.lazy">
      </route>
    </router>
  `
})
export class MyComponent {
  components = {
    lazy: () => import('./lazy/lazy.component').then(m => m.LazyComponent)
  }
}