Angular刷新/重新加载路由器将URL更新为默认路由。如何停止?
当我尝试重新加载URL时,页面会刷新默认导航。我想停止它,然后再次重新加载相同的URL。这就是我的路由模块的样子:
const routes: Routes = [
{
path: 'store', component: AppComponent, children:
[
{ path: 'public', component: HomeComponent, data: { defaultSelectedTab: 0 } },
{ path: 'public/softwares', component: HomeComponent, data: { selectedValue: 'softwares', defaultSelectedTab: 0 } },
{ path: 'public/softwares/:id', component: SoftwareDetailsComponent },
{ path: '', redirectTo: "public", pathMatch: 'full' },
]
},
{
path: '**', component: EmptyComponent
}
];
@NgModule({
imports: [RouterModule.forRoot(routes, { useHash: true, onSameUrlNavigation: 'reload'})],
exports: [RouterModule]
})
export class AppRoutingModule { }
我试图做这样的事情,而每个独立路径成为前一个孩子的孩子:
{
path: 'public',
component: HomeComponent,
data: { defaultSelectedTab: 0 },
children: [
{
path: 'softwares',
component: HomeComponent,
data: { selectedValue: 'softwares', defaultSelectedTab: 0 },
children: [
{
path: ':id',
component: SoftwareDetailsComponent
}
]
}
]
},
{ path: '', redirectTo: "public", pathMatch: 'full' },
但是,这个人甚至没有将其路由到正确的组件。我试图从回答最大投票。如果在AppComponent中指定了路由器输出的帮助。我仍然不确定我在做什么错。任何帮助都非常感谢。
When I am trying to reload the url, the page refreshes to the default navigation. I want to stop that and reload the same url again. This is how my routing module looks like:
const routes: Routes = [
{
path: 'store', component: AppComponent, children:
[
{ path: 'public', component: HomeComponent, data: { defaultSelectedTab: 0 } },
{ path: 'public/softwares', component: HomeComponent, data: { selectedValue: 'softwares', defaultSelectedTab: 0 } },
{ path: 'public/softwares/:id', component: SoftwareDetailsComponent },
{ path: '', redirectTo: "public", pathMatch: 'full' },
]
},
{
path: '**', component: EmptyComponent
}
];
@NgModule({
imports: [RouterModule.forRoot(routes, { useHash: true, onSameUrlNavigation: 'reload'})],
exports: [RouterModule]
})
export class AppRoutingModule { }
I tried to do something like this where each of the independent path become a children of the previous one:
{
path: 'public',
component: HomeComponent,
data: { defaultSelectedTab: 0 },
children: [
{
path: 'softwares',
component: HomeComponent,
data: { selectedValue: 'softwares', defaultSelectedTab: 0 },
children: [
{
path: ':id',
component: SoftwareDetailsComponent
}
]
}
]
},
{ path: '', redirectTo: "public", pathMatch: 'full' },
But then this one doesn't even route it to the right component. I was trying to take a clue from the answer with the max votes. If in case it helps the router-outlet is specified in AppComponent. Still I am not sure what am I doing wrong. Any help is much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论