Angular刷新/重新加载路由器将URL更新为默认路由。如何停止?

发布于 2025-02-11 13:39:44 字数 1654 浏览 0 评论 0原文

当我尝试重新加载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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文