방금 새 라우팅 라이브러리 (@ angular / 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 버전을 사용할 때도 동일한 오류가 나타납니다.)
app.component.ts
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 {
}
app.routes.ts
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)
];
home.ts
import { Component } from '@angular/core';
@Component({
template: '<h1>Home Page</h1>'
})
export class HomePage {
}
main.ts
/* 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));
'<router-outlet></router-outlet>'
이 것은 너무에 오타 오류 때문일 수 있습니다'<router-outlet></router-outlet>'