我很好奇你是如何在路由模块数组上skipLocationChange的。
onst routes: Routes = [
{ path: '', redirectTo: '/login', pathMatch: 'full' },
{ path: 'login', component: LoginComponent },
{ path: 'register', component: RegisterComponent },
{ path: 'dashboard', component: DashboardComponent },
{ path: 'createentry', component: CreateentryComponent },
{ path: 'dateview', component: DateviewComponent },
{path: 'profile', component: ProfileComponent},
{ path: 'calendar', component: CalendarComponent, resolve: { singlePost: SinglePostResolver}}
];我在开始时自动重定向到登录,但是如何跳过这里附加的Url呢?
发布于 2021-02-19 10:08:11
在不改变路由器配置位置的情况下,不可能导航。您可能会做一个护卫,它将在路径导航中被激活,并将重定向所带来的一切。
const routes = [
{ path: '', canActivate: [RedirectGuard], data: {redirectTo: '/login'}, pathMatch: 'full' },
...
]export class RedirectGuard {
constructor(private router: Router) {}
canActivate(routeSnapshot) {
this.router.navigateByUrl(routeSnapshot.data.redirectTo, {skipLocationChange: true});
}
}https://stackoverflow.com/questions/66275151
复制相似问题