代码之家  ›  专栏  ›  技术社区  ›  Vik

相对于根的角度材质路由器导航

  •  0
  • Vik  · 技术社区  · 7 年前

    在我的项目中,我遇到了单击按钮无法导航的情况,例外情况如下:

    core.es5.js:1020 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'workarea/homepage'
    Error: Cannot match any routes. URL Segment: 'workarea/homepage'
        at ApplyRedirects.webpackJsonp.../../../router/@angular/router.es5.js.ApplyRedirects.noMatchError (router.es5.js:1466)
        at CatchSubscriber.selector (router.es5.js:1441)
        at CatchSubscriber.webpackJsonp.../../../../rxjs/_esm5/operators/catchError.js.CatchSubscriber.error (catchError.js:105)
        at MapSubscriber.webpackJsonp.../../../../rxjs/_esm5/Subscriber.js.Subscriber._error (Subscriber.js:130)
        at MapSubscriber.webpackJsonp.../../../../rxjs/_esm5/Subscriber.js.Subscriber.error (Subscriber.js:104)
        at MapSubscriber.webpackJsonp.../../../../rxjs/_esm5/Subscriber.js.Subscriber._error (Subscriber.js:130)
        at MapSubscriber.webpackJsonp.../../../../rxjs/_esm5/Subscriber.js.Subscriber.error (Subscriber.js:104)
        at MapSubscriber.webpackJsonp.../../../../rxjs/_esm5/Subscriber.js.Subscriber._error (Subscriber.js:130)
        at MapSubscriber.webpackJsonp.../../../../rxjs/_esm5/Subscriber.js.Subscriber.error (Subscriber.js:104)
        at LastSubscriber.webpackJsonp.../../../../rxjs/_esm5/Subscriber.js.Subscriber._error (Subscriber.js:130)
        at ApplyRedirects.webpackJsonp.../../../router/@angular/router.es5.js.ApplyRedirects.noMatchError (router.es5.js:1466)
    

    它正在尝试导航到不存在且正确的工作区/家庭。我不知道它为什么要这样做。我希望它导航到/家,而不是工作区/家。我需要什么样的修复。路由器文件如下所示:

    const appRoutes: Routes = [ 
        {
            path: '',
            component: LoginPageComponent
        },
         {
            path: 'homepage',
            component: DynamicHomeComponent
        },
        {
            path: 'workarea',
            component: WorkareaPageComponent
        },
         {
            path: 'workarea-typeb',
            component: WorkareaTypebPageComponent
        }
    
    ];
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   Ayman El Temsahi Roevic    7 年前

    在路由器链接中,添加正斜杠 / 链接之前

    而不是

    routerLink='home'
    

    尝试

    routerLink='/home'