微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

angularjs – Angular 2 Rc.1路由器未加载“/”组件

我试图使用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

If you have routes setup without any router links and you don’t inject the router,initial navigation does not occur.

因此要么注入路由器,要么添加< a [routerLink] =“...”>直到此问题得到解决.

原文地址:https://www.jb51.cc/angularjs/140929.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐