我有类似以下的URL:
www.yoursite.com/accounts/:accountid/info
www.yoursite.com/accounts/:accountid/users
等。
URL中有一个整数值accountid
,但无法使用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
的参数。