Chr*_*ien 3 brackets parentheses angular2-routing angular
我有一个包含一系列组件的 Angular 5 应用程序。有些组件是其他组件的子组件,有些则不是。
我希望应用程序具有如下结构:
*/my-account/overview // homepage
*/my-account/my-stuff
*/profile
*/non-default
Run Code Online (Sandbox Code Playgroud)
我有一个 DefaultComponent ,其中包含一些通用元素,例如我希望在大多数页面上出现的站点导航(除 */非默认路由/组件外的所有内容)。
我的路由模块定义了以下路由:
export const routes: Routes = [
{ path: '', redirectTo: 'my-account', pathMatch: 'full' }, // should redirect to localhost:4200/my-account
{ path: '', component: DefaultComponent, children: [
{ path: 'my-account', children: [
{ path: '', redirectTo: 'overview', pathMatch: 'full' }, // should redirect to localhost:4200/my-account/overview
{ path: 'overview', component: OverviewComponent }, // should resolve: localhost:4200/my-account/overview
{ path: 'my-stuff', component: MyStuffComponent } // should resolve: localhost:4200/my-account/my-stuff
]},
{ path: 'profile', component: ProfileComponent } // should resolve: localhost:4200/profile
]},
{ path: 'non-default', component: NonDefaultComponent } // should resolve: localhost:4200/non-default
];
Run Code Online (Sandbox Code Playgroud)
如果我直接在浏览器中点击 URL,这些路由会完美解析。我遇到的问题是,当我尝试使用 [routerLink] 指令呈现锚点时,实际应用于 href 的 URL 是
href="/my-account/overview/(profile)"
而不是
href="/个人资料"
对于 ProfileComponent。因此,如果我使用 [routerLink] 呈现导航项列表,则每个项都有一个实际上并未解析为组件的 href。
如果有帮助,我有一个Github 存储库在这里演示这个问题。
我是否错误地配置了路由?
正如Eliseo正确指出的那样。我在 RouterLink 本身的路由开始处遗漏了一个斜线。
[routerLink]=['我的账户/概览']
本来应该
[routerLink]=['/my-account/overview']
值得注意的是,在我引入子路由之前,它一直运行良好。
| 归档时间: |
|
| 查看次数: |
2857 次 |
| 最近记录: |