我有像这样的网址
www.yoursite.com/accounts/:accountid/info
www.yoursite.com/accounts/:accountid/users
等等
accountid
URL 中有一个整数值
但无法使用ActivatedRoute
参数访问它。
现在我正在拆分 URL 以获取accountid
除了拆分 URL 之外,还有更好的方法来访问该值吗?
更新
我有一个不同的模块account
,其中包括帐户相关页面的所有组件和服务。
我懒加载这个模块。所以在根级路由中,app-routing
我指定
{ path:'account', loadChildren : './account/account.module#AccountModule' }
在帐户模块中account-routing
,我指定孩子
path: 'account/:accountid', component: AccountComponent, canActivate: [AuthGuard],
children: [
{ path: '', redirectTo: 'info', pathMatch: 'full' },
{ path: 'info', component: InfoComponent },
{ path: 'users, component: UsersComponent }
{path: '**', redirectTo: 'info'}
]
笔记 :
如果存在,我们可以访问子路径中的参数。但不是父级的,为什么?
我正在获取undefined
父路径中的参数