Angular UI Components Documentation
The Angular Router maps URLs to components: typing a URL, following a link or pressing the browser's Back button shows the matching view without reloading the page. This guide builds a small routed app with jQWidgets components - a list of heroes in a jqxGrid, a detail page for each hero, a lazy-loaded page and a guarded one - in a standalone Angular 22 app.
ng new heroes-router --routing
cd heroes-router
ng add jqwidgets-ng
--routing creates src/app/app.routes.ts and registers the router in src/app/app.config.ts. ng add asks for a theme and adds the jQWidgets styles to angular.json.
A service holds the heroes. Components ask it for them with inject():
// src/app/hero.service.ts
import { Injectable } from '@angular/core';
export interface Hero { id: number; name: string; power: string; }
@Injectable({ providedIn: 'root' })
export class HeroService {
readonly heroes: Hero[] = [
{ id: 11, name: 'Dr. Nice', power: 'Empathy' },
{ id: 12, name: 'Bombasto', power: 'Volume' },
{ id: 13, name: 'Celeritas', power: 'Speed' },
{ id: 14, name: 'Magneta', power: 'Magnetism' },
{ id: 15, name: 'RubberMan', power: 'Elasticity' }
];
get(id: number): Hero | undefined {
return this.heroes.find(h => h.id === id);
}
}
Each route pairs a path with a component. :id is a route parameter; loadComponent loads a page only when it is first visited; ** catches every other URL.
// src/app/app.routes.ts
import { Routes } from '@angular/router';
import { HeroList } from './hero-list';
import { HeroDetail } from './hero-detail';
import { NotFound } from './not-found';
import { adminGuard } from './admin.guard';
export const routes: Routes = [
{ path: '', redirectTo: 'heroes', pathMatch: 'full' },
{ path: 'heroes', component: HeroList, title: 'Heroes' },
{ path: 'hero/:id', component: HeroDetail, title: 'Hero' },
{ path: 'admin', loadComponent: () => import('./admin').then(m => m.Admin), canActivate: [adminGuard], title: 'Admin' },
{ path: '**', component: NotFound, title: 'Not found' }
];
Register them in app.config.ts. withComponentInputBinding() passes route parameters to components as inputs, so the detail page gets the hero's id without reading the route itself:
// src/app/app.config.ts
import { ApplicationConfig } from '@angular/core';
import { provideRouter, withComponentInputBinding } from '@angular/router';
import { routes } from './app.routes';
export const appConfig: ApplicationConfig = {
providers: [provideRouter(routes, withComponentInputBinding())]
};
src/main.ts starts the app with that configuration (the CLI writes this for you):
import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { App } from './app/app';
bootstrapApplication(App, appConfig);
The root component shows the navigation and a <router-outlet>, where the router places the component of the current route. routerLink navigates without a page load; routerLinkActive adds a class to the link of the current route.
// src/app/app.ts
import { Component } from '@angular/core';
import { RouterLink, RouterLinkActive, RouterOutlet } from '@angular/router';
@Component({
selector: 'app-root',
imports: [RouterOutlet, RouterLink, RouterLinkActive],
template: `
<nav>
<a routerLink="/heroes" routerLinkActive="active">Heroes</a>
<a routerLink="/admin" routerLinkActive="active">Admin</a>
</nav>
<router-outlet />
`
})
export class App {}
The heroes page shows the heroes in a jqxGrid. Clicking a row navigates to that hero's page with Router.navigate, the code equivalent of routerLink:
// src/app/hero-list.ts
import { Component, inject, viewChild } from '@angular/core';
import { Router } from '@angular/router';
import { jqxGridComponent, jqxGridModule } from 'jqwidgets-ng/jqxgrid';
import { HeroService } from './hero.service';
@Component({
selector: 'app-hero-list',
imports: [jqxGridModule],
template: `
<h1>Heroes</h1>
<jqxGrid
#grid
[width]="'100%'"
[autoheight]="true"
[source]="dataAdapter"
[columns]="columns"
(onRowclick)="open($event)"
>
</jqxGrid>
`
})
export class HeroList {
private readonly router = inject(Router);
readonly grid = viewChild.required<jqxGridComponent>('grid');
readonly dataAdapter = new jqx.dataAdapter({
localdata: inject(HeroService).heroes,
datatype: 'array',
datafields: [
{ name: 'id', type: 'number' },
{ name: 'name', type: 'string' },
{ name: 'power', type: 'string' }
]
});
readonly columns: jqwidgets.GridColumn[] = [
{ text: 'Id', datafield: 'id', width: 80 },
{ text: 'Name', datafield: 'name' },
{ text: 'Power', datafield: 'power' }
];
open(event: any): void {
const hero = this.grid().getrowdata(event.args.rowindex);
this.router.navigate(['/hero', hero.id]);
}
}
Because the grid navigates with the router, the Back button returns to the list, and /hero/13 can be bookmarked or shared.
With withComponentInputBinding(), the :id of hero/:id arrives as the component's id input - a signal, so the hero is a computed value that follows the URL:
// src/app/hero-detail.ts
import { Component, computed, inject, input } from '@angular/core';
import { RouterLink } from '@angular/router';
import { jqxInputModule } from 'jqwidgets-ng/jqxinput';
import { HeroService } from './hero.service';
@Component({
selector: 'app-hero-detail',
imports: [RouterLink, jqxInputModule],
template: `
@if (hero(); as hero) {
<h1>{{ hero.name }}</h1>
<label
>Power <jqxInput [value]="hero.power" [width]="240" [height]="32"></jqxInput
></label>
} @else {
<p>There is no hero with the id {{ id() }}.</p>
}
<p><a routerLink="/heroes">Back to the heroes</a></p>
`
})
export class HeroDetail {
readonly id = input.required<string>();
private readonly heroes = inject(HeroService);
readonly hero = computed(() => this.heroes.get(Number(this.id())));
}
A guard decides whether navigation may continue. Guards are functions: return true to allow it, or a UrlTree to send the user somewhere else.
// src/app/admin.guard.ts
import { inject } from '@angular/core';
import { CanActivateFn, Router } from '@angular/router';
import { AuthService } from './auth.service';
export const adminGuard: CanActivateFn = () =>
inject(AuthService).isAdmin() || inject(Router).parseUrl('/heroes');
The admin page is loaded lazily (loadComponent in step 3), so its code - and the jQWidgets components it imports - is downloaded only when an allowed user first opens it.
Router.events reports every step of a navigation. For example, to close an open jqxWindow or jqxMenu when the page changes:
import { DestroyRef, inject } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { NavigationEnd, Router } from '@angular/router';
import { filter } from 'rxjs';
inject(Router).events
.pipe(filter(e => e instanceof NavigationEnd), takeUntilDestroyed(inject(DestroyRef)))
.subscribe(() => this.window().close());
ng serve
Open http://localhost:4200: the app redirects to /heroes. Click a row to open a hero, use Back to return, and try an unknown URL to see the not-found page.
Next: Grid getting started, reactive forms with jQWidgets, and the Angular routing guide.