Angular route: redirectTo 当使用多个参数时
Angular route: redirectTo when using multiple param
我有这样的路线
const pipelinesRoutes: Routes = [
{
path: ':type',
component: CatalogComponent,
canActivate: [LoggedInGuard],
children: [
{
path: '',
component: CatalogContentComponent,
},
{
path: ':domain/:categoryId',
component: CatalogContentComponent,
},
],
},
{ path: '', redirectTo: 'skills', canActivate: [LoggedInGuard] },
];
如果没有提供类型,我想将我的应用程序重定向到 skills(:type),它在启动时工作正常,但是一旦我刷新说有这个 url。
catalog/skills/technical
它重定向到
catalog/skills/skills/technical
感谢 T. Sunil Rao 帮助我。
是的,我的路线有问题。
我在
的帮助下进行路由时传递了空参数
this.router.navigate([domain, ''], { relativeTo: this.route });
但是刷新时它不会将空参数视为如此重定向的参数。
catalog/skills/technical 没有完全填满任何路线所以它重定向到技能/
正确的路线应该是
const pipelinesRoutes: Routes = [
{ path: '', redirectTo: 'skills', pathMatch: 'full' },
{
path: ':type',
component: CatalogComponent,
canActivate: [LoggedInGuard],
children: [
{
path: '',
component: NoDomainContentComponent,
},
{
path: ':domain',
component: CatalogContentComponent,
children: [
{
path: ':categoryId',
component: CatalogContentComponent,
},
]
},
],
},
];
使用另一个子组件,因为我不想刷新组件,想使用相同的组件并只过滤数据。
我有这样的路线
const pipelinesRoutes: Routes = [
{
path: ':type',
component: CatalogComponent,
canActivate: [LoggedInGuard],
children: [
{
path: '',
component: CatalogContentComponent,
},
{
path: ':domain/:categoryId',
component: CatalogContentComponent,
},
],
},
{ path: '', redirectTo: 'skills', canActivate: [LoggedInGuard] },
];
如果没有提供类型,我想将我的应用程序重定向到 skills(:type),它在启动时工作正常,但是一旦我刷新说有这个 url。
catalog/skills/technical
它重定向到
catalog/skills/skills/technical
感谢 T. Sunil Rao 帮助我。 是的,我的路线有问题。 我在
的帮助下进行路由时传递了空参数this.router.navigate([domain, ''], { relativeTo: this.route });
但是刷新时它不会将空参数视为如此重定向的参数。
catalog/skills/technical 没有完全填满任何路线所以它重定向到技能/ 正确的路线应该是
const pipelinesRoutes: Routes = [
{ path: '', redirectTo: 'skills', pathMatch: 'full' },
{
path: ':type',
component: CatalogComponent,
canActivate: [LoggedInGuard],
children: [
{
path: '',
component: NoDomainContentComponent,
},
{
path: ':domain',
component: CatalogContentComponent,
children: [
{
path: ':categoryId',
component: CatalogContentComponent,
},
]
},
],
},
];
使用另一个子组件,因为我不想刷新组件,想使用相同的组件并只过滤数据。