【问题标题】:RouterLink url changes to default url while opening new tabRouterLink url 在打开新标签时更改为默认 url
【发布时间】:2023-03-31 20:36:01
【问题描述】:

Routerlink url 不应更改为默认 url..

当我使用 RouterModule.forRoot(appRoutes, { useHash: true });它工作正常.. 但我改为 useHash = false,它不工作

在 html 中我使用了这个代码:

<a routerLink="/applicationredirect" [queryParams]="{appId: recentMenu.applicationId}">{{recentMenu.applicationMasterName}} - {{recentMenu.applicationCode}}</a>

路由页面:

const appRoutes: Routes = [
       .....
 {
   path: 'applicationredirect', component: ApplicationRedirectComponent,
 },
  {
path: 'home', component: HomeComponent,
   }
  ...
// otherwise redirect to home
{ path: '**', redirectTo: 'home' }
  ];
const StartupRouting = RouterModule.forRoot(appRoutes, { useHash: false });

当我在新标签页中打开时,

首先我得到了,

localhost:4200/applicationredirect?appId=1084518

然后变成这个,

localhost:4200#/home

我终于得到了这个默认页面

localhost:4200/home#/home

我希望 (localhost:4200/applicationredirect?appId=1084518) 网址打开..

【问题讨论】:

    标签: angular angular-routerlink


    【解决方案1】:

    这是正常行为。几点:

    • 如果你想调用没有哈希的路由,不要提供第二个参数{ useHash: ... }
    • 您没有在路由器配置对象中声明 applicationredirect 段,因此在您声明它之前,它将回退到 /home 路由,因为您将其设置为 { path: '**', redirectTo: 'home' }
    • 如果您在任何模块中有它,请删除它:{ provide: LocationStrategy, useClass: HashLocationStrategy },因为 PathLocationStrategy 是 default strategy

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-14
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多