【发布时间】:2017-09-17 18:14:48
【问题描述】:
在下面的路由中,我在尝试获取 http://localhost:4200/ 时收到以下错误
错误错误:未捕获(承诺):错误:无法重定向到“/:userCountry/:userLanguage/home”。找不到“:userCountry”。 错误:无法重定向到“/:userCountry/:userLanguage/home”。找不到“:userCountry”。 在 ApplyRedirects.webpackJsonp.../../../router/@angular/router.es5.js.ApplyRedirects.findPosParam (router.es5.js:1784)
所有其他路由路径都在工作,只有 redirectTo 似乎没有替换变量 userCountry(以及 userLanguage)的值。
任何帮助将不胜感激。
const appRoutes: Routes = [
{ path: '', redirectTo: '/:userCountry/:userLanguage/home', pathMatch: 'full' },
{ path: ':userCountry/:userLanguage/home', component: HomeComponent },
{ path: ':userCountry/:userLanguage/about', loadChildren: './about/about.module#AboutModule' },
{ path: ':userCountry/:userLanguage/terms', loadChildren: './terms/terms.module#TermsModule' },
{ path: ':userCountry/:userLanguage/privacy', loadChildren: './privacy/privacy.module#PrivacyModule' },
{ path: '**', component: PageNotFoundComponent }
];
当错误出现时,我的变量已经有值了。
这是我的 console.log() 的摘录
[AppRoutingModule.constructor]this.userLanguage=fr
[AppRoutingModule.constructor]this.userCountry=ca
...
ERROR Error: Uncaught (in promise): Error: Cannot redirect to '/:userCountry/:userLanguage/home'. Cannot find ':userCountry'
【问题讨论】: