我试图使用rc.0版本中的新路由器. (实际使用rc.1)但是我无法获得加载“欢迎”组件的插座.
这是app.component.ts
import { Component } from '@angular/core'; import { Routes,ROUTER_DIRECTIVES} from '@angular/router'; import { HeaderComponent } from './common/header.component'; import { WelcomeComponent } from './common/welcome.component'; import { FooterComponent } from './common/footer.component'; @Component({ selector: 'my-app',template: ` <header-component> </header-component> <router-outlet> </router-outlet> <footer-component> <footer-component> `,directives: [ROUTER_DIRECTIVES,HeaderComponent,WelcomeComponent,FooterComponent] }) @Routes([ {path: "/",component: WelcomeComponent} ]) export class AppComponent { }
这是main.ts
import { bootstrap } from '@angular/platform-browser-dynamic'; import {ROUTER_PROVIDERS} from '@angular/router'; import { AppComponent } from './app.component'; bootstrap(AppComponent,[ROUTER_PROVIDERS]);
我不确定我失踪了什么,/应该工作的路径. index.html的基本引用也设置为“/”.我一直在挖掘源头,看看我遗失了什么,但没有找到任何东西.
这是一个已知问题
https://github.com/angular/angular/issues/8409
原文链接:https://www.f2er.com/angularjs/140929.htmlIf you have routes setup without any router links and you don’t inject the router,initial navigation does not occur.