Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
angular-routing-test
Advanced tools
A declarative router for Angular applications.
Use your package manager of choice to install the package.
npm install angular-routing
OR
yarn add angular-routing
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>
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>
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>
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('/');
}
}
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);
}
}
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);
}
}
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;
}
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)
}
}
0.1.1 (2020-07-02)
BEFORE:
<route path="/path" [loadComponent]=""></route>
AFTER:
<route path="/path" [load]=""></route>
FAQs
A declarative router for Angular applications
The npm package angular-routing-test receives a total of 0 weekly downloads. As such, angular-routing-test popularity was classified as not popular.
We found that angular-routing-test demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.