我试图理解角度2路由的工作方式。我已经定义了两个子路径路径& movieCategory / create'和路径:' movieCategory', 当我键入http://localhost:4200/#/movieCategory时,它工作正常并显示MovieCategory组件。但是当我向浏览器输入http://localhost:4200/#/movieCategory/create时,它会显示CreateMovieCategory组件,但网址又会变为http://localhost:4200/#/movieCategory。 我究竟做错了什么 ? 第二个问题#来自哪里?
我的路线
export const routes: Routes = [
{
path: '',
redirectTo: 'movieCategory',
pathMatch: 'full',
},
{
path: '',
component: FullLayoutComponent,
data: {
title: 'Film Kategorileri'
},
children: [
{
path: 'movieCategory/create',
component: CreateMovieCategory
},
{
path: 'movieCategory',
component: MovieCategory
}
]
}
];
我还有一个按钮,当我点击它时会显示相同的行为。
<button class="btn btn-primary pull-right" type="button" [routerLink]="['/movieCategory/create']">
提前致谢
答案 0 :(得分:0)
export const routeConfig:Routes = [
{
path: '',
component: FullLayoutComponent
}
{
path: 'movieCategory',
children: [
{
path: 'create',
component: CreateMovieCategory
}
]
}
];
有关详细信息,请查看此LINK。
如果您使用PathLocationStrategy作为描述here,则可以删除网址中的哈希值。