如何限制Angular2路由参数?
给出这个简单的路由示例,我希望能够限制如何限制Angular2路由参数?,angular,routing,Angular,Routing,给出这个简单的路由示例,我希望能够限制:page参数 const appRoutes: Routes = [ { path: ':page', component: PageFoundComponent }, { path: '**', component: PageNotFoundComponent } ]; 最好使用字符串数组。此处的预期行为是检查:page是否为数组元素之一,如果不存在,则路由到PageNotFoundComponent // pseudo code let kn
:page
参数
const appRoutes: Routes = [
{ path: ':page', component: PageFoundComponent },
{ path: '**', component: PageNotFoundComponent }
];
最好使用字符串数组。此处的预期行为是检查:page
是否为数组元素之一,如果不存在,则路由到PageNotFoundComponent
// pseudo code
let knownPages = ["welcome", "shop", "about"];
(...)
{ path: ':page@knownPages', component: PageFoundComponent }
这一概念借用了Symfony2路由机制
我应该怎么做 您可以使用最近引入的自定义
UrlMatcher
{ path: ':page', component: PageFoundComponent, matcher: ... },
但是我还没有找到任何关于它的文档
另请参见您将要使用路由器。具体来说,很可能是
从“../auth-guard.service”导入{AuthGuard};
const adminRoutes:路由=[
{
路径:':第页',
组件:组件,
canActivate:[AuthGuard]
}
];
@NGD模块({
进口:[
RouterModule.forChild(adminRoutes)
],
出口:[
路由模块
]
})
导出类路由模块{}