• Overview
@angular/router

RedirectFunction

Type Alias

The type for the function that can be used to handle redirects when the path matches a Route config.

API

  
    type RedirectFunction = (  redirectData: Pick<    ActivatedRouteSnapshot,    'routeConfig' | 'url' | 'params' | 'queryParams' | 'fragment' | 'data' | 'outlet' | 'title'  >,) => string | UrlTree
  
  

Description

The type for the function that can be used to handle redirects when the path matches a Route config.

The RedirectFunction does have access to the full ActivatedRouteSnapshot interface. Some data are not accurately known at the route matching phase. For example, resolvers are not run until later, so any resolved title would not be populated. The same goes for lazy loaded components. This is also true for all the snapshots up to the root, so properties that include parents (root, parent, pathFromRoot) are also excluded. And naturally, the full route matching hasn't yet happened so firstChild and children are not available either.

Jump to details