Spec-Zone.ru › Angular

RedirectCommand

Can be returned by a Router guard to instruct the Router to redirect rather than continue processing the path of the in-flight navigation. The redirectTo indicates where the new navigation should go to and the optional navigationBehaviorOptions can provide more information about how to perform the navigation.

Routing guide

API

class RedirectCommand {
  constructor(redirectTo: UrlTree, navigationBehaviorOptions?: NavigationBehaviorOptions | undefined): RedirectCommand;
}

constructor

RedirectCommand
@paramredirectToUrlTree
@paramnavigationBehaviorOptionsNavigationBehaviorOptions | undefined
@returnsRedirectCommand

Description

Can be returned by a Router guard to instruct the Router to redirect rather than continue processing the path of the in-flight navigation. The redirectTo indicates where the new navigation should go to and the optional navigationBehaviorOptions can provide more information about how to perform the navigation.

const route: Route = {
  path: "user/:userId",
  component: User,
  canActivate: [
    () => {
      const router = inject(Router);
      const authService = inject(AuthenticationService);

      if (!authService.isLoggedIn()) {
        const loginPath = router.parseUrl("/login");
        return new RedirectCommand(loginPath, {
          skipLocationChange: true,
        });
      }

      return true;
    },
  ],
};

Super-powered by Google ©2010–2025.
Code licensed under an MIT-style License. Documentation licensed under CC BY 4.0.
https://angular.dev/api/router/RedirectCommand

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API