Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Angular Router’s “other routing tasks” include reading route information, showing a not-found page, and building links with route parameters. Define specific routes before broad ones, place the wildcard route last, and use RouterLink for in-app navigation. These patterns build on a route configuration that maps URL paths to rendered views.

How Angular Router handles routes

Angular Router is Angular’s official client-side routing library. In a single-page application, the browser first requests the app document; after that, the router can update the displayed view as the URL changes without replacing the entire page. A route can select a component, load a component or child route configuration lazily, attach data, resolve data, set a title, redirect, or participate in guard checks. See Angular’s routing overview and the Route API reference.

The examples below use standalone route objects and components. Define the routes in the router configuration used by your application; the specific file and bootstrap setup can vary by project.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Show a not-found page for unmatched paths

A wildcard route matches paths that did not match an earlier route. Put it after all known routes so it cannot intercept a path intended for a specific page. Angular’s route definition guide explains route matching and order; its common routing tasks guide shows the not-found pattern.

const routes: Routes = [
  { path: 'products', component: ProductList },
  { path: 'products/:id', component: ProductDetail },
  { path: '**', component: PageNotFound },
];

With this order, the router can match the known product paths before reaching the wildcard. If ** appears earlier, it may capture paths that should match routes below it. Test one known URL and at least one unknown URL to check both outcomes.

Redirect a path deliberately

Use redirectTo to send a matching path elsewhere. The pathMatch setting determines how much of the URL must match: 'full' requires the whole path, while 'prefix' matches an initial segment and is the default. An empty-path redirect commonly needs 'full', preventing it from matching every URL that begins with the empty path.

const routes: Routes = [
  { path: '', redirectTo: '/home', pathMatch: 'full' },
  { path: 'home', component: HomePage },
];

For legacy URLs, a parameterized redirect can preserve an identifier when the old and new path shapes are compatible. Review Angular’s redirecting routes guide before choosing the match rule, especially when a redirect uses a broad prefix.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read route information in a component

Route values can reach a component through component input binding or through route-state APIs such as ActivatedRoute. The appropriate choice depends on the Angular version and the application’s routing setup. Component input binding lets route values be exposed as component inputs; consult the common routing tasks guide for its current guidance and examples.

Choose a single approach that fits the component and configuration rather than assuming every app exposes route state in the same way. If maintaining older code, check how that app currently reads route parameters before changing its pattern.

Build in-app links with RouterLink

Use Angular’s RouterLink directive in a template for navigation within the application. A parameter array is useful when a link includes route parameters, because each array item represents part of the navigation path.

<a [routerLink]="['/products', product.id]">
  View product
</a>

For a route such as products/:id, the array supplies the products path segment and the product’s identifier. Angular’s common routing tasks guide covers link parameter arrays.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Know what lazy loading and guards do

Lazy loading and route guards address different concerns. Lazy loading defers route code until it is needed; a guard participates in deciding whether navigation proceeds. Route configuration supports both, but a browser-side guard is not a substitute for server-side authorization: protect data and resources where they are served as well. See the routing overview and the Route API reference.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.