路由''的无效配置:redirectTo和canActivate不能一起使用

问题描述 投票:0回答:1

我想做 laravel angular jwt 身份验证,所以我想应用防护,但它给我错误:

Invalid configuration of route '': redirectTo and canActivate cannot be used together. Redirects happen before activation so canActivate will never be executed
.

app-routing.module.ts

const routes: Routes = [
  { path:"", redirectTo:"/adress", pathMatch:'full', canActivate:[AuthGuard] },
];
angular guard canactivate
1个回答
1
投票

RedirectTo 和canActivate 不能同时使用。重定向发生在激活之前,因此 canActivate 永远不会被执行。

在 Angular 14 中,您不能再在同一配置中同时使用它们。在您的检查/路由配置中选择 redirectTo 和 CanActivate,为您的情况保留最可靠的,您应该很高兴。

您可以在以下链接中找到更多详细信息:https://stackoverflow.com/a/74052870/4983912.

我希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.