October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Angular redirectTo: Choose a destination and match routes correctly

Configure Angular redirects for default routes, legacy paths, route parameters, and unknown URLs—with clear guidance on pathMatch and route order.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Configure an Angular route redirect with redirectTo in your route configuration. Use pathMatch: 'full' for an exact match—especially an empty-path default route—and place redirects and fallback routes in an order that does not intercept routes meant to match later.

Set up a basic route redirect

Angular’s official routing documentation says, “Route redirects allow you to automatically navigate users from one route to another.” Add redirectTo to the route whose path should forward visitors. The destination can be a string or a function. Angular’s redirecting routes guide shows examples for legacy paths, parameterized paths, and wildcard routes.

As an Amazon Associate I earn from qualifying purchases.

import { Routes } from '@angular/router';

export const routes: Routes = [
  { path: 'marketing', redirectTo: 'newsletter' },
  // Other routes follow.
];

Here, a visit to marketing is redirected to newsletter. Choose the destination route deliberately: redirects are useful for forwarding old links and bookmarks when the new destination is appropriate.

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

Choose pathMatch for the behavior you want

pathMatch determines how much of the URL path must match the route. Angular defaults it to 'prefix'; that can be useful when a redirect should also apply to paths that continue beyond the matched prefix. Use 'full' when the redirect should apply only if the entire path matches. The Route API reference documents the default and matching behavior.

Setting Matching behavior Good fit
prefix (default) The route path can match the start of the URL path, including URLs with later segments. A redirect intended to cover a prefix and its nested paths.
full The complete URL path must match. An exact-path redirect or a default redirect from the empty path.

For example, Angular’s guide illustrates a news prefix redirect that also applies to news/article. Use that behavior only when nested paths should go to the corresponding redirect destination.

Redirect the empty path to a default route

An empty path is a prefix of every URL. If an empty-path redirect uses the default prefix match, it can match too broadly and cause unwanted navigation or a redirect loop. Set pathMatch: 'full' so the redirect applies only to the root path.

export const routes: Routes = [
  { path: '', redirectTo: '/dashboard', pathMatch: 'full' },
  // Other routes follow.
];

This pattern sends the empty root path to /dashboard, while allowing other paths to be considered by their own routes.

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

Choose an absolute or relative destination

A redirect destination that begins with / is absolute. A destination without the leading slash is resolved relative to the route path. The Route API describes this distinction; use the form that matches the intended destination rather than relying on an assumed base path.

  • redirectTo: '/dashboard' targets the absolute /dashboard path.
  • redirectTo: 'newsletter' resolves the destination relative to the route path.

Preserve a parameter when moving a legacy URL

If the old and new routes use the same parameter, include it in both paths. Angular’s redirecting routes guide demonstrates forwarding an ID from legacy-user/:id to users/:id.

{ path: 'legacy-user/:id', redirectTo: 'users/:id' }

Make sure the destination route accepts that parameter, then check representative legacy URLs in your application to confirm they reach the intended destination.

Use a function for a conditional redirect

Set redirectTo to a function when the destination depends on route or query parameters. The function can return a string or a UrlTree; the API type also permits asynchronous results. See the Angular guide’s conditional redirect examples and Route API reference.

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

A redirect function runs during route matching, before matching is complete. It receives only partial route snapshot data, so do not make its decision depend on information that may not yet be available, such as resolved titles or lazy-loaded components. Keep the condition tied to data available at that stage.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Order routes so the intended route can match

Angular uses a first-match-wins strategy. Put specific route patterns before general ones, and keep a wildcard route after routes intended to handle known paths. An earlier broad match can prevent a later route from being considered. Angular explains route ordering in its route definition guide.

  1. List specific paths and parameterized routes that should handle known URLs.
  2. Add broader routes only after the routes they could otherwise intercept.
  3. Put the ** wildcard last so it handles only paths not matched earlier.

Decide what unknown URLs should do

A wildcard route can display a not-found component or redirect to another destination. Choose based on the intended experience: a not-found page keeps the invalid path visible, while a redirect takes the visitor somewhere useful when that is the desired behavior. Angular documents both approaches in its redirecting routes guide and route definition guide.

export const routes: Routes = [
  // Known routes go first.
  { path: '**', component: NotFoundComponent },
];

To redirect instead, configure the wildcard with redirectTo and select a destination appropriate for your application. Avoid using a catch-all redirect when showing the user that a URL is invalid is important.

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

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.