最佳答案
我刚开始使用新的路由库(@angle/router v3.0.0-alpha.7) ,但是按照官方的 医生会导致以下错误:
browser_adapter.ts:74: EXCEPTION: Error: Uncaught (in promise): Error: Cannot find primary outlet to load 'HomePage'
问题是——我如何消除错误并使路由器按预期行事?我错过什么了吗?
(在使用 alpha.6版本时会出现同样的错误。)
应用程序组件
import { Component } from '@angular/core';
import { ROUTER_DIRECTIVES } from '@angular/router';
@Component({
selector: 'app',
template: `
<p>Angular 2 is running...</p>
<!-- Routed views go here -->
<router-outlet></router-outlet>
`,
providers: [ROUTER_DIRECTIVES]
})
export class AppComponent {
}
应用程序路由
import { provideRouter, RouterConfig } from '@angular/router';
import { HomePage } from './pages/home/home';
export const routes: RouterConfig = [
{ path: '', component: HomePage }
];
export const APP_ROUTER_PROVIDERS = [
provideRouter(routes)
];
家
import { Component } from '@angular/core';
@Component({
template: '<h1>Home Page</h1>'
})
export class HomePage {
}
Mats
/* Avoid: 'error TS2304: Cannot find name <type>' during compilation */
///<reference path="../../typings/index.d.ts" />
import { bootstrap } from "@angular/platform-browser-dynamic";
import { APP_ROUTER_PROVIDERS } from './app.routes';
import { AppComponent } from "./app.component";
bootstrap(AppComponent, [
APP_ROUTER_PROVIDERS,
]).catch(err => console.error(err));