2016-03-01 58 views
1

當前正在使用angular2 beta版本6,在父級到子級使用(EX:/ plan/...)的嵌套路由中,未來不適用於es5 JavaScript開發,但在鍵入腳本開發它的工作完美Angular2嵌套路由父級到子級ES5不工作

投擲錯誤:EXCEPTION:鏈接「[」計劃「]」不解析爲終端指令。

App.js代碼

var Tabs = [],viewId; 

app.AppComponent = 
    ng.core.Component({ 
     selector: 'app', 
     template: '<router-outlet></router-outlet>', 
     directives: [ng.router.ROUTER_DIRECTIVES], 
     providers: [ng.http.HTTP_PROVIDERS] 
    }) 

    .Class({ 

     constructor: [ng.router.Router, function(router) { 
      console.log("1"); 
      router.config([ 
       { path: '/', redirectTo: ['Home'] }, 
       { path: '/home', component: app.HomeComponent, name: 'Home' }, 
       { path: '/plan/...', component: app.planComponent, name: 'Plan' } 
      ]); 
     }] 
    }); 

document.addEventListener('DOMContentLoaded', function() { 
    ng.platform.browser.bootstrap(app.AppComponent,[ng.router.ROUTER_PROVIDERS]); 
}); 

Plan.js代碼

app.planComponent = 
    ng.core.Component({ 
     selector: 'plan-view', 
     templateUrl: './assets/src/plan/view/plan.html', 
     directives: [ ng.router.RouterLink, ng.router.ROUTER_DIRECTIVES], 
    }) 
    .Class({ 
     constructor:[ng.router.Router, function(router){ 
      console.log("2"); 
      router.config([ 
       { path: '/', redirectTo: ['PlanInfo'] }, 
       { path: '/planInfo', component: app.planInfoComponent, name: 'PlanInfo', useAsDefault: true }/*, 
       { path: '/coverage', component: app.CoverageComponent, name: 'Coverage' }, 
       { path: '/nonelective', component: app.nonElectiveComponent, name: 'NonElective' }, 
       { path: '/loans', component: app.loansComponent, name: 'Loans' }, 
       { path: '/enrollment', component: app.enrollmentComponent, name: 'Enrollment' }*/ 
      ]); 
     }] 
    }); 

回答

0

我認爲你應該使用ng.router.RouteConfig裝飾,而不是路由器本身的。像這樣,您將擁有與TypeScript相同的配置。

這裏是做的方式:

ng.router 
    .RouteConfig([ 
     { path: '/', redirectTo: ['Home'] }, 
     { path: '/home', component: app.HomeComponent, name: 'Home' }, 
     { path: '/plan/...', component: app.planComponent, name: 'Plan' } 
    ])(app.AppComponent); 

(...) 

ng.router 
    .RouteConfig([ 
     { path: '/', redirectTo: ['PlanInfo'] }, 
     { path: '/planInfo', component: app.planInfoComponent, name: 'PlanInfo', useAsDefault: true }/*, 
     { path: '/coverage', component: app.CoverageComponent, name: 'Coverage' }, 
     { path: '/nonelective', component: app.nonElectiveComponent, name: 'NonElective' }, 
     { path: '/loans', component: app.loansComponent, name: 'Loans' }, 
     { path: '/enrollment', component: app.enrollmentComponent, name: 'Enrollment' }*/ 
    ])(app.planComponent); 

作爲參考,你可以看看這個plunkr:https://plnkr.co/edit/w61Ecbmuj7EfDnsYEHOS?p=info

相關問題