Angular 2 Router 3.0.0 嵌套路由编译
Angular 2 Router 3.0.0 Nested Routes Compiling
我似乎在使用 Angular 2 的新路由器 3.0.0-alpha.8 时遇到了问题。
长话短说,我的 app.routes.ts 是
export const routes: RouterConfig = [
{ path: '', component: HomeComponent, canActivate: [AuthGuard] },
{ path: 'login', component: LoginComponent },
...SectionARoutes,
...SectionBRoutes
];
export const APP_ROUTER_PROVIDERS = [
provideRouter(routes),
AUTH_PROVIDERS
];
它加载 A 段路线很好,它是:
export const SectionARoutes: RouterConfig = [
{ path: 'a', component: SectionAComponent, canActivate: [AuthGuard] },
{ path: 'a-more', component: SectionAMoreComponent, canActivate: [AuthGuard] },
...SectionAMoreRoutes
];
但是它无法加载嵌套的 SectionAMoreRoutes。当我说加载失败时,我的意思是我得到的错误是:
zone.js:463 Error: Uncaught (in promise): Error: Error: XHR error (404 Not Found)
loading http://localhost:4200/app/+a/+a-more/a-more.routes.ts.js(…)
当路由被嵌套时,我的打字稿似乎没有被编译成 js。我很想得到任何关于如何进行的帮助或想法,因为我很迷茫:(
谢谢!!!
额外信息:
我的 main.ts 有:
bootstrap(AppComponent, [
...
APP_ROUTER_PROVIDERS,
]
Section-a-more 路线如下:
export const SectionARoutes: RouterConfig = [
{ path: '', component: SectionAMoreListComponent, canActivate: [AuthGuard] },
{ path: '/:id', component: SectionAMoreDetailComponent, canActivate: [AuthGuard] }
];
TLDR:为什么我的嵌套路由不能在 Angular 2 和 Router 3.0.0
中编译
为了解决这个问题,我疯狂了 2 天。
尝试删除 app.routes.js 文件(不是 TS 文件)
然后在命令行输入
tsc app/app.routes.ts
(或者您路由文件所在的位置)。
这应该重新编译并创建一个新的 app.route.js 文件。
我似乎在使用 Angular 2 的新路由器 3.0.0-alpha.8 时遇到了问题。
长话短说,我的 app.routes.ts 是
export const routes: RouterConfig = [
{ path: '', component: HomeComponent, canActivate: [AuthGuard] },
{ path: 'login', component: LoginComponent },
...SectionARoutes,
...SectionBRoutes
];
export const APP_ROUTER_PROVIDERS = [
provideRouter(routes),
AUTH_PROVIDERS
];
它加载 A 段路线很好,它是:
export const SectionARoutes: RouterConfig = [
{ path: 'a', component: SectionAComponent, canActivate: [AuthGuard] },
{ path: 'a-more', component: SectionAMoreComponent, canActivate: [AuthGuard] },
...SectionAMoreRoutes
];
但是它无法加载嵌套的 SectionAMoreRoutes。当我说加载失败时,我的意思是我得到的错误是:
zone.js:463 Error: Uncaught (in promise): Error: Error: XHR error (404 Not Found)
loading http://localhost:4200/app/+a/+a-more/a-more.routes.ts.js(…)
当路由被嵌套时,我的打字稿似乎没有被编译成 js。我很想得到任何关于如何进行的帮助或想法,因为我很迷茫:(
谢谢!!!
额外信息: 我的 main.ts 有:
bootstrap(AppComponent, [
...
APP_ROUTER_PROVIDERS,
]
Section-a-more 路线如下:
export const SectionARoutes: RouterConfig = [
{ path: '', component: SectionAMoreListComponent, canActivate: [AuthGuard] },
{ path: '/:id', component: SectionAMoreDetailComponent, canActivate: [AuthGuard] }
];
TLDR:为什么我的嵌套路由不能在 Angular 2 和 Router 3.0.0
中编译为了解决这个问题,我疯狂了 2 天。
尝试删除 app.routes.js 文件(不是 TS 文件)
然后在命令行输入
tsc app/app.routes.ts
(或者您路由文件所在的位置)。
这应该重新编译并创建一个新的 app.route.js 文件。