Den*_*lek 8 javascript router angular
更新11/1/15
从Alpha 45开始,Aux Routes不受支持. 链接到Github问题
@ evan-plaice的道具
原始问题
我在Angular2路由器上观看了Brian Ford的演讲:https://youtu.be/z1NB-HG0ZH4
我开始尝试使用"Aux"路由,我的代码丢失了很多错误.
我在mgechev的Angular Seed的Alpha 44上
在我的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' }
])
Run Code Online (Sandbox Code Playgroud)
我的app.html:
<div id="main-content" class="full">
<router-outlet></router-outlet>
<router-outlet name="login"></router-outlet>
</div>
Run Code Online (Sandbox Code Playgroud)
在HomeCmp中我放了一个"登录"链接:
<p>Router Link to activate login form: <a [router-link]="['/',['Login']]">Login</a></p>
Run Code Online (Sandbox Code Playgroud)
现在我在该组件中有其他路由器链接工作正常,但是当我添加此链接时给出了这个错误:
例外:
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
Run Code Online (Sandbox Code Playgroud)
错误:
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)
Run Code Online (Sandbox Code Playgroud)
语境:
{element: a, componentElement: home, context: HomeCmp, locals: Object, injector: Injector…}
Run Code Online (Sandbox Code Playgroud)
它还抛出这个:
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)
Run Code Online (Sandbox Code Playgroud)
但它是在第一个错误之后所以我不确定它是由第一个还是什么造成的.
我也尝试过Angular2 API Docs中的Way, 但它会抛出相同的错误.
注意:我尝试让路由器使用Plunker,但它不喜欢URL或其他我提供的实时案例
更新10/29/15 第一个错误来自路由器链接,不允许您以任何方式使用"\"或".\".您必须指定路线名称.
Aux仍然不起作用......
routerLink 匹配数组中第一个参数的路径
在你的情况下它会匹配/或Home
<a [routerLink]="['/',['Login']]">Login</a>
Run Code Online (Sandbox Code Playgroud)
使用这个代替:
<a [routerLink]="['/Login']">Login</a>
Run Code Online (Sandbox Code Playgroud)
AFAIK,该参数是一个数组,因为路由还可以包含一个或多个通配符匹配。
注意:Login链接中使用的 指向路由的别名(即字段as)。
来源:
更新:
请留意。angular2 团队计划在未来版本中将RouterLink/更改<router-link>为RouterViewport/ 。<router-viewport>
资料来源:角度/问题#4679
更新2:
| 归档时间: |
|
| 查看次数: |
2102 次 |
| 最近记录: |