双击后,带有[RouterLink]结果,可导航到默认路由的侧菜单项

发布于 2025-02-09 03:26:27 字数 2523 浏览 2 评论 0原文

我在Angular应用程序上的侧面菜单上解决了一些错误,当我两次单击侧面菜单项时,我总是将其重定向到默认路由。如下面的屏幕截图所示,当我单击财务年度菜单项时,我将被重定向到付款帐户路由。是什么可能导致这种行为?

我在Sidemenu项目上使用RouterLink

如下所示,我正在使用Routerlink

...
<div class="category-children" *ngIf="rlaAcc.isActive">
    <!-- Section Bank Accounts -->
    <div mat-list-item id="item-accounting-transfers" data-intercom-target="Accounting module transfers"
      [routerLink]="['/accounting', property.id, 'transfers']" routerLinkActive="active-child"
      #rlaAccBank="routerLinkActive" class="child-header">
    </div>
    <div class="category-children" *ngIf="rlaAccBank.isActive">
      <div mat-list-item id="item-accounting-transfers" data-intercom-target="Accounting module transfers"
        [routerLink]="['/accounting', property.id, 'transfers', 'currents']" routerLinkActive="active-sub-child"
        class="child-header">

      </div>
      <div mat-list-item id="item-accounting-transfers" data-intercom-target="Accounting module transfers"
        [routerLink]="['/accounting', property.id, 'transfers', 'savings']" routerLinkActive="active-sub-child"
        class="child-header">
 
      </div>
    </div>
...

会计路线

    export const ACCOUNTING_ROUTES: Route[] = [
       ....
      // Default link
      { 
        path: ':propId',
        redirectTo: '/accounting/:propId/transfers/currents',
        pathMatch: 'full', data:{propId:[`:propId`]},
        canActivate: [IsOnboardedGuard]
      },
      { path: ':propId/financial-years', loadChildren: () => import('@xyz/features/accounting/financial-years/main').then(m => m.FinancialYearsHomeModule), canActivate: [IsOnboardedGuard] },
   
     ......
    
    ];

财政年度路线

const FINANCIAL_YEAR_ROUTES: Routes = [
  { path: '', component: FinancialYearsHomePage,
    children: [
      { path:'', redirectTo: 'overview', pathMatch: 'full'},
      { path: 'overview', component: FYearsOverviewPage }
    ],
  },

];

路线日志我的测试环境

”在此处输入图像说明”

I'm resolving some bug on the side menu on an Angular application, when I click on the side menu item twice I'm always redirected to the default route. As shown from the screenshot below when I click on the Financial years menu item I will be redirected to the Payment Account route. What might be causing this behavior?

I'm using routerLink on the sidemenu Items.

enter image description here

As you can see below I'm using routerLink

...
<div class="category-children" *ngIf="rlaAcc.isActive">
    <!-- Section Bank Accounts -->
    <div mat-list-item id="item-accounting-transfers" data-intercom-target="Accounting module transfers"
      [routerLink]="['/accounting', property.id, 'transfers']" routerLinkActive="active-child"
      #rlaAccBank="routerLinkActive" class="child-header">
    </div>
    <div class="category-children" *ngIf="rlaAccBank.isActive">
      <div mat-list-item id="item-accounting-transfers" data-intercom-target="Accounting module transfers"
        [routerLink]="['/accounting', property.id, 'transfers', 'currents']" routerLinkActive="active-sub-child"
        class="child-header">

      </div>
      <div mat-list-item id="item-accounting-transfers" data-intercom-target="Accounting module transfers"
        [routerLink]="['/accounting', property.id, 'transfers', 'savings']" routerLinkActive="active-sub-child"
        class="child-header">
 
      </div>
    </div>
...

Accounting ROUTES

    export const ACCOUNTING_ROUTES: Route[] = [
       ....
      // Default link
      { 
        path: ':propId',
        redirectTo: '/accounting/:propId/transfers/currents',
        pathMatch: 'full', data:{propId:[`:propId`]},
        canActivate: [IsOnboardedGuard]
      },
      { path: ':propId/financial-years', loadChildren: () => import('@xyz/features/accounting/financial-years/main').then(m => m.FinancialYearsHomeModule), canActivate: [IsOnboardedGuard] },
   
     ......
    
    ];

Financial Year ROUTES

const FINANCIAL_YEAR_ROUTES: Routes = [
  { path: '', component: FinancialYearsHomePage,
    children: [
      { path:'', redirectTo: 'overview', pathMatch: 'full'},
      { path: 'overview', component: FYearsOverviewPage }
    ],
  },

];

Route Logs from my test environment

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掐死时间 2025-02-16 03:26:27

似乎问题是路由组件无法在同一URL上重新加载。为了在同一URL导航上重新加载组件,我将设置为onSameUrlNAvigation reload ,并提供 routereusestrategy false 在组件上均应false 。

import { Router } from '@angular/router';

constructor(private _router: Router){}

ngOnInit()
  {
    this._router.routeReuseStrategy.shouldReuseRoute = () => false;
    this._router.onSameUrlNavigation = 'reload';
  }

Seems like the issue was the routed component could not reload on the same url. In order to reload routed components on same url navigation, I set onSameUrlNavigation to reload and provide a RouteReuseStrategy which returns false for shouldReuseRoute on the component.

import { Router } from '@angular/router';

constructor(private _router: Router){}

ngOnInit()
  {
    this._router.routeReuseStrategy.shouldReuseRoute = () => false;
    this._router.onSameUrlNavigation = 'reload';
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文