angular: RouteLink annotation throws an exception
From @ElsewhereGames on June 20, 2016 16:11
Tried to switch from the deprecated router to alpha 7 of this one, but I am not able to use routeLinks in on my child routes. I have a list of routes like this:
<a [routerLink]="['inputs']">Inputs</a>
<a [routerLink]="['outputs']">Test</a>
When I first open the page with these links, none of them appear to be clickable (in other words, no hand cursor on mouse-over). When I do click any of the links, the console shows an error:
Uncaught EXCEPTION: Error in ./NavigationLinkComponent class NavigationLinkComponent - inline template:0:0
ORIGINAL EXCEPTION: TypeError: Cannot read property 'length' of undefined
ORIGINAL STACKTRACE:
TypeError: Cannot read property 'length' of undefined
at UrlParser.parseSegmentChildren (http://127.0.0.1:8181/scripts/vendors.js:76681:28)
at UrlParser.parseRootSegment (http://127.0.0.1:8181/scripts/vendors.js:76677:56)
at DefaultUrlSerializer.parse (http://127.0.0.1:8181/scripts/vendors.js:76554:42)
at Router.navigateByUrl (http://127.0.0.1:8181/scripts/vendors.js:75894:47)
at RouterLink.onClick (http://127.0.0.1:8181/scripts/vendors.js:75718:22)
at DebugAppView._View_NavigationLinkComponent0._handle_click_0_0 (NavigationLinkComponent.template.js:67:36)
at http://127.0.0.1:8181/scripts/vendors.js:41217:25
at http://127.0.0.1:8181/scripts/vendors.js:66297:37
at http://127.0.0.1:8181/scripts/vendors.js:67190:112
at ZoneDelegate.invoke (http://127.0.0.1:8181/scripts/vendors.js:19012:30)
My source maps point me to this line:
if (this.remaining.length == 0) {
return {};
}
I looked around for a demo project or starting plunker, but I was not able to find one yet (the documentation uses alpha 3). Any help is appreciated!
Copied from original issue: angular/vladivostok#91
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 27 (11 by maintainers)
@zacharyclaysmith I’m seeing the same error:
Some investigation:
RouterLinkWithHref
updates itsurlTree
property whenngOnChanges()
fires, but that isn’t happening beforeonClick()
fires so we end up being unable to schedule navigation properly.@artuska https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith Support of String.prototype.startsWith started in Safari 9. So you simply need some sort of polyfill RTM: https://angular.io/guide/browser-support#polyfill-libs
use 2.0.0-rc.4
2016-08-07 12:38 GMT-05:00 tiboprea notifications@github.com:
Gerardo Andres Gutierrez RodriguezTecnólogo en Sistematización de Datos UDFJC * *Ingeniero en Telemática UDFJC
@robwormald I’m also getting a very similar error when trying to use routeLink. Not sure of the current status of this issue. Here’s the error as output in the browser:
ORIGINAL EXCEPTION: TypeError: Cannot read property 'startsWith' of undefined ORIGINAL STACKTRACE: TypeError: Cannot read property 'startsWith' of undefined at UrlParser.parseRootSegment (eval at <anonymous> (http://localhost:3000/vendor.bundle.js:1743:2), <anonymous>:303:27) at DefaultUrlSerializer.parse (eval at <anonymous> (http://localhost:3000/vendor.bundle.js:1743:2), <anonymous>:200:30) at Router.navigateByUrl (eval at <anonymous> (http://localhost:3000/vendor.bundle.js:1545:2), <anonymous>:243:46) at RouterLinkWithHref.onClick (eval at <anonymous> (http://localhost:3000/vendor.bundle.js:1539:2), <anonymous>:89:21) at DebugAppView._View_LeftNavComponent0._handle_click_10_0 (LeftNavComponent.template.js:504:45) at eval (eval at <anonymous> (http://localhost:3000/vendor.bundle.js:674:2), <anonymous>:375:24) at eval (eval at <anonymous> (http://localhost:3000/vendor.bundle.js:1333:2), <anonymous>:254:36) at eval (eval at <anonymous> (http://localhost:3000/vendor.bundle.js:1345:2), <anonymous>:27:111) at ZoneDelegate.invoke (eval at <anonymous> (http://localhost:3000/polyfills.bundle.js:2671:2), <anonymous>:323:29) at Object.onInvoke (eval at <anonymous> (http://localhost:3000/vendor.bundle.js:500:2), <anonymous>:53:41)
I’m using webpack, and get this for any/all routeLinks used within templates that are nested within a parent
<router-outlet>
. Let me know what other info you need. For now, I’m doing a work-around using click events and manual routing.I just did a quick test, and this tag “works” on a root level template:
<a [routerLink]="['/hello']">hello</a>
but breaks with the above error on child templates (i.e. templates rendered within a router-outlet component).
*Snippet of current Angular dependencies from package.json: “@angular/common”: “2.0.0-rc.4”, “@angular/compiler”: “2.0.0-rc.4”, “@angular/core”: “2.0.0-rc.4”, “@angular/forms”: “^0.2.0”, “@angular/http”: “2.0.0-rc.4”, “@angular/platform-browser”: “2.0.0-rc.4”, “@angular/platform-browser-dynamic”: “2.0.0-rc.4”, “@angular/router”: “3.0.0-beta.2”, “@angular/upgrade”: “2.0.0-rc.4”,
Update: When I remove most of the code from my app, I basically end up with the following:
routerLink
outside of a<router-outlet>
works fine.routerLink
inside of a<router-outlet>
doesn’t seem to get processed.What I mean by this is that the link in the outlet does not the
ng-reflect-router-link
orng-reflect-href
attributes assigned.I still am not able to reproduce this behavior with a plunkr.