angular material 相对于 root 的路由器导航
angular material router navigation with respect to root
我在我的项目中遇到了这样一种情况,即单击按钮无法导航并出现异常:
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
}
];
在您的路由器 link 中,在 link
之前添加正斜杠 /
而不是
routerLink='home'
尝试
routerLink='/home'
我在我的项目中遇到了这样一种情况,即单击按钮无法导航并出现异常:
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
}
];
在您的路由器 link 中,在 link
之前添加正斜杠/
而不是
routerLink='home'
尝试
routerLink='/home'