Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
957 views
in Technique[技术] by (71.8m points)

typescript - Angular2 RouterLink breaks routes by replacing slash with %2F

Since the latest Angular2 version (2.0.0-beta.14) it is possible to have query parameters that contain multiple slashes, like /foo/bar.

This works great, however whenever I use a parameter with multiple slashes within a RouterLink link, it escapes the / with %2F causing the routes to not work anymore on reload.

My link looks like this: <a [routerLink]="['/Page', {page: page.url | slug}]" class="list-group-item">{{ page.title }}</a>

Inside of the 'slug' pipe I even URIDecode the string, and when I log it it is correct. It would log something like /pages/level-1/, but when I inspect the actual a tag on the page it says href="/pages%2Flevel-1".

I'm pretty clueless, because even when I print the value of {{ page.url | slug }} within my HTML template, it returns the url with slashes.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...