组件“AppComponent”没有路由配置,路由器未定义以进行导航

时间:2016-07-19 09:36:25

标签: angular

import { Component } from 'angular2/core'; 
import { Router } from 'angular2/router';    
import { RouteConfig } from 'angular2/router';   
import { ROUTER_DIRECTIVES } from 'angular2/router';    
import { LandingComponent } from './landing.component';     

@RouteConfig([    
    {path: '/landing', name: 'Landing', component: LandingComponent},   
    {path: '/*other', name: 'Other', redirectTo: ['Landing']}     
]);       

@Component({     
    selector: 'cwf',    
    templateUrl: 'app/template/index.template.html',   
    directives: [ROUTER_DIRECTIVES]     
})    

export class AppComponent {    

    constructor(private _router:Router){

    }     

    browserObject = BrowserDetect;    
    navigator =  navigator.javaEnabled() ? "enabled" : "disabled";  
    listBrowser = BrowserDetect.supportedBrowser;    

    ngOnInit(){    
        let timer = Observable.timer(2000);  
        timer.subscribe(this.navigate);     
    };    

    navigate = () => {  
        this._router.navigate(['Landing']);  
    };      

}

1 个答案:

答案 0 :(得分:2)

删除

末尾的;
@RouteConfig([    
    {path: '/landing', name: 'Landing', component: LandingComponent},   
    {path: '/*other', name: 'Other', redirectTo: ['Landing']}     
]);