1
我正在使用Angular 2路由器3.0.0-beta.2。Angular 2路由器錯誤:路由'undefined'的配置無效
似乎無法獲得一條工作路線。
「錯誤:路由的無效配置 '未定義':成分redirectTo,兒童必須提供」
main.ts
import { bootstrap } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppComponent, environment, appRouterProviders } from './app';
bootstrap(AppComponent, [appRouterProviders])
.catch(err => console.error(err));
app.routes.ts
import {provideRouter, RouterConfig} from '@angular/router';
import {HomeComponent} from './';
export const appRoutes:RouterConfig = [
[{
path: '',
redirectTo: '/home',
pathMatch: 'full'
},{
path: 'home',
component: HomeComponent
}]
];
export const routes: RouterConfig = [
...appRoutes
];
export const appRouterProviders = [
provideRouter(routes)
];
app.component.ts
import { Component } from '@angular/core';
import { ROUTER_DIRECTIVES } from '@angular/router';
@Component({
moduleId: module.id,
selector: 'app-root',
templateUrl: 'app.component.html',
directives: [ROUTER_DIRECTIVES]
})
export class AppComponent {
title = 'app works!';
}
個
home.component.ts
import { Component, OnInit } from '@angular/core';
import { ROUTER_DIRECTIVES } from '@angular/router';
@Component({
moduleId: module.id,
selector: 'app-home',
templateUrl: 'home.component.html',
directives: [ROUTER_DIRECTIVES]
})
export class HomeComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
app.component.html
<h1>
App Shell
</h1>
<router-outlet></router-outlet>
哦天啊..複製並粘貼錯誤!謝謝! – JBeckton
仍然有相同的錯誤 –