【发布时间】:2017-04-21 02:28:02
【问题描述】:
我们在此处提供了子路由定义,其中我们使用保护来检查用户在使用我们的服务之前是否已接受条款。
account/secret/secret.routes.ts:
import { Routes } from '@angular/router';
import { SecretFormComponent } from './secret-form.component';
import { SecretTermsComponent } from './secret-terms.component';
import { TermsGuard } from './services/terms-guard.service';
export const secretRoutes: Routes = [
{
path: '',
redirectTo: 'form'
},
{
path: 'form',
component: SecretFormComponent,
canActivate: [TermsGuard]
},
{ path: 'terms', component: SecretTermsComponent }
// otherwise redirect to form
{ path: '**', redirectTo: 'form' }
];
在我们的术语守卫中,我们定义了以下代码:
this.router.navigate(['/account/secret/terms']);
return false;
有没有办法在“路由组”中使用相对路由导航进行重定向?因为如果有一天我们的帐户网站仪表板被重命名为其他任何东西,例如 my-account,那么定义绝对路径可能会中断。我们希望我们的秘密模块是可重用的。
我希望能够在我的警卫中导航到['./terms'],但它不起作用,就像警卫不知道“从哪里”开始相对导航一样。
【问题讨论】: