2015-10-28 73 views
8

UPDATE 15年11月1日Angular2路由器恨我的AUX路线

辅助路线,不支持很好阿尔法的45 Link to Github Issue

道具@埃文 - 鲽

原问题

我看了Brian Ford在Angular2路由器上的讲话:https://youtu.be/z1NB-HG0ZH4

我开始尝试使用“辅助”路线,我的代码投掷了大量的错误。

我在阿尔法44mgechev's Angular Seed

在我app.ts组件这是非常标准的,为RouteConfig我有:

@RouteConfig([ 
    { path: '/', component: HomeCmp, as: 'Home' }, 
    { path: '/run', component: RunCmp, as: 'Run' }, 
    { path: '/manage', component: ManageCmp, as: 'Manage' }, 
    { path: '/user', component: UserCmp, as: 'User' }, 
    { path: '/settings', component: LocalSettingsCmp, as: 'Settings' }, 
    { aux: '/login', component: LoginCmp, as: 'Login' } 
]) 

我app.html:

<div id="main-content" class="full"> 
    <router-outlet></router-outlet> 
    <router-outlet name="login"></router-outlet> 
</div> 

HomeCmp我把一个“登录”链接:

<p>Router Link to activate login form: <a [router-link]="['/',['Login']]">Login</a></p> 

现在我已经在正常工作该组件的其他路由器的链接,但是当我添加此链接给我这个错误:

例外:

EXCEPTION: "/" is only allowed at the beginning of a link DSL. in [null] 
BrowserDomAdapter.logError @ angular2.dev.js?v=0.0.0:21835 
BrowserDomAdapter.logGroup @ angular2.dev.js?v=0.0.0:21846 
ExceptionHandler.call @ angular2.dev.js?v=0.0.0:4431 
(anonymous function) @ angular2.dev.js?v=0.0.0:19543 
NgZone._onError @ angular2.dev.js?v=0.0.0:10711 
errorHandling.onError @ angular2.dev.js?v=0.0.0:10630 
run @ angular2.dev.js?v=0.0.0:141 
(anonymous function) @ angular2.dev.js?v=0.0.0:10651 
zoneBoundFn @ angular2.dev.js?v=0.0.0:111 
lib$es6$promise$asap$$flush @ angular2.dev.js?v=0.0.0:1301 
angular2.dev.js?v=0.0.0:21835 

错误:

Error: "/" is only allowed at the beginning of a link DSL. 
    at new BaseException (http://localhost:5555/lib/angular2.dev.js?v=0.0.0:16034:21) 
    at RouteRegistry.generate (http://localhost:5555/lib/router.dev.js?v=0.0.0:1645:17) 
    at ChildRouter.Router.generate (http://localhost:5555/lib/router.dev.js?v=0.0.0:2044:43) 
    at RouterLink.Object.defineProperty.set [as routeParams] (http://localhost:5555/lib/router.dev.js?v=0.0.0:1323:52) 
    at AbstractChangeDetector.ChangeDetector_HomeCmp_0.detectChangesInRecordsInternal (eval at <anonymous> (http://localhost:5555/lib/angular2.dev.js?v=0.0.0:20415:14), <anonymous>:118:40) 
    at AbstractChangeDetector.detectChangesInRecords (http://localhost:5555/lib/angular2.dev.js?v=0.0.0:20209:14) 
    at AbstractChangeDetector.runDetectChanges (http://localhost:5555/lib/angular2.dev.js?v=0.0.0:20192:12) 
    at AbstractChangeDetector._detectChangesInShadowDomChildren (http://localhost:5555/lib/angular2.dev.js?v=0.0.0:20259:14) 
    at AbstractChangeDetector.runDetectChanges (http://localhost:5555/lib/angular2.dev.js?v=0.0.0:20196:12) 
    at AbstractChangeDetector._detectChangesInLightDomChildren (http://localhost:5555/lib/angular2.dev.js?v=0.0.0:20253:14) 

上下文:

{element: a, componentElement: home, context: HomeCmp, locals: Object, injector: Injector…} 

也抛出这个:

TypeError: Cannot read property 'child' of undefined 
    at ChildRouter.Router.isRouteActive (http://localhost:5555/lib/router.dev.js?v=0.0.0:1803:77) 
    at RouterLink.Object.defineProperty.get [as isRouteActive] (http://localhost:5555/lib/router.dev.js?v=0.0.0:1315:29) 
    at AbstractChangeDetector.ChangeDetector_HomeCmp_0.detectChangesInRecordsInternal (eval at <anonymous> (http://localhost:5555/lib/angular2.dev.js?v=0.0.0:20415:14), <anonymous>:153:44) 
    at AbstractChangeDetector.detectChangesInRecords (http://localhost:5555/lib/angular2.dev.js?v=0.0.0:20209:14) 
    at AbstractChangeDetector.runDetectChanges (http://localhost:5555/lib/angular2.dev.js?v=0.0.0:20192:12) 
    at AbstractChangeDetector._detectChangesInShadowDomChildren (http://localhost:5555/lib/angular2.dev.js?v=0.0.0:20259:14) 
    at AbstractChangeDetector.runDetectChanges (http://localhost:5555/lib/angular2.dev.js?v=0.0.0:20196:12) 
    at AbstractChangeDetector._detectChangesInLightDomChildren (http://localhost:5555/lib/angular2.dev.js?v=0.0.0:20253:14) 
    at AbstractChangeDetector.runDetectChanges (http://localhost:5555/lib/angular2.dev.js?v=0.0.0:20193:12) 
    at AbstractChangeDetector._detectChangesInShadowDomChildren (http://localhost:5555/lib/angular2.dev.js?v=0.0.0:20259:14) 

不过,所以我不知道,如果它造成第一还是什么的第一个错误后,它的。

我也试过Way from the Angular2 API Docs 但它会引发相同的错误。

  • 我做错了什么?
  • 该语法不支持吗?
  • 有没有人正确使用Aux Routes的例子?

注:我试图让路由器与Plunker工作,但它不喜欢的URL或东西,否则我会提供了一个现场情况

UPDATE 15年10月29日 的第一个错误是来自路由器链接,不让你以任何方式使用“\”或“。\”。你必须指定路由名称。

辅助仍然无法正常工作......

回答

3

的routerLink的第一个参数的路径匹配阵列

在你的情况下,它会匹配/Home

<a [routerLink]="['/',['Login']]">Login</a> 

改为使用:

<a [routerLink]="['/Login']">Login</a> 

AFAIK,参数是一个数组,因为路由也可以包含一个或多个通配符匹配。

注意:链接中使用的Login指向路由的别名(即as字段)。

来源:

更新:

留意。 angular2团队计划在未来的版本中将RouterLink/<router-link>更改为RouterViewport/<router-viewport>

来源:angular/issues#4679

UPDATE2:

  • [路由器链路] - > [routerLink]
+1

我相信他们正在改变'<路由器出口>'而不是'' –

+0

因此,您的链接对于**标准**路由器链接是正确的,但是当使用多个网点和“Aux”链接时, w使用数组作为第二个参数来指定辅助的名称。哪一个不起作用......其目的是在一个组件上有多个'',但它对我不起作用。我的使用案例是一个登录/注册表格,这是谈话的例子... –

+0

是的...我意识到事后。看起来他们仍在工作https://github.com/angular/angular/issues/4319 –