首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >skipLocationChange在线路阵列上。角11

skipLocationChange在线路阵列上。角11
EN

Stack Overflow用户
提问于 2021-02-19 09:43:20
回答 1查看 443关注 0票数 0

我很好奇你是如何在路由模块数组上skipLocationChange的。

代码语言:javascript
复制
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呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-19 10:08:11

在不改变路由器配置位置的情况下,不可能导航。您可能会做一个护卫,它将在路径导航中被激活,并将重定向所带来的一切。

代码语言:javascript
复制
const routes = [
 { path: '', canActivate: [RedirectGuard], data: {redirectTo: '/login'}, pathMatch: 'full' },
...
]
代码语言:javascript
复制
export class RedirectGuard {
  constructor(private router: Router) {}
  canActivate(routeSnapshot) {
    this.router.navigateByUrl(routeSnapshot.data.redirectTo, {skipLocationChange: true});
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66275151

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档