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

时间:2018-01-25 00:20:40

标签: angular angular-material router

我遇到的情况是我的项目中单击按钮无法导航,但例外情况为:

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)

它试图导航到workarea / home,这是不存在的,这是正确的。我不知道为什么会这样尝试。我希望它导航到/ home而不是workarea / home。我需要什么修复。路由器文件如下所示:

const appRoutes: Routes = [ 
    {
        path: '',
        component: LoginPageComponent
    },
     {
        path: 'homepage',
        component: DynamicHomeComponent
    },
    {
        path: 'workarea',
        component: WorkareaPageComponent
    },
     {
        path: 'workarea-typeb',
        component: WorkareaTypebPageComponent
    }

];

1 个答案:

答案 0 :(得分:2)

在路由器链接中

,在链接

之前添加正斜杠/

而不是

routerLink='home'

尝试

routerLink='/home'