Angular2 RouterLink breaks routes by replacing slash with %2F
If the path was something like
pathServedByTheController = 'foo/bar'
then in the view I can do something like
<my-button (click)="onEmitCta()" [routerLink]="['/'].concat(pathServedByTheController.split('/')).concat('')" class="banner-cta inverse shadow">NAVIGATE</my-button>
This works nicely to me!
You need to replace comma(,) with (+) like this
Wrong => <a [routerLink]="['/Page', page.url]" class="list-group-item">{{ page.title }}</a>
Right => <a [routerLink]="['/Page' + page.url]" class="list-group-item">{{ page.title }}</a>
So I found the solution thanks to the Angular2 Issues page on Github (thanks Günter!).
My route was configured like this:
({
path: "/:page",
component: Page,
name: "Page"
}),
but instead should have been
({
path: "/*page",
component: Page,
name: "Page"
}),
Difference is the *
wildcard in front of page
.
I created this issue
Instead of trying to use strings with slashes in routerLink, we simply let the router handle it in the component.
<a (click)="goToPage(url)">Link</a>
url = 'group/8';
goToPage(url) {
this.router.navigateByUrl(url);
}