routerLink绝对网址 [英] routerLink absolute url
问题描述
来自角度文档:>
router link指令始终将提供的输入视为增量 到当前网址.
The router link directive always treats the provided input as a delta to the current url.
例如,如果当前URL是/user/(box//aux:team)
.然后
以下链接<a [routerLink]="['/user/jim']">Jim</a>
将生成
链接/user/(jim//aux:team)
.
For instance, if the current url is /user/(box//aux:team)
. Then the
following link <a [routerLink]="['/user/jim']">Jim</a>
will generate
the link /user/(jim//aux:team)
.
那么您如何创建指向/user/jim
的链接?
So how do you create a link to /user/jim
?
我尝试了['/user/jim', { outlets: { aux: null }}]
,但是这不起作用.
即使有效,它也不是最佳解决方案.我宁愿寻找一种导航到绝对URL的方法,而不是取消可能渠道.
I tried ['/user/jim', { outlets: { aux: null }}]
but this isn't working.
Even if it worked it wouldn't have been a optimal solution. I'm rather looking for a way to navigate to an absolute url than cancelling possibles outlets.
在同一主题上,我有一个指向根目录的链接:routerLink="/"
就是这样做的,它重定向到我的应用程序的根目录,而没有像绝对链接这样的出口.有趣的是,我不是特别希望特定链接具有该行为,因此保持所有出口路线都很好...
On the same subject I have a link to the root : routerLink="/"
that does just that, it redirect to the root of my application without any outlets like an absolute link. What's funny here is I don't specially want that behavior for that particular link, keeping any outlets routes was fine...
推荐答案
截至2018年8月,角度文档说:
As of August, 2018, Angular docs say:
- 如果第一段以/开头,则路由器将从应用程序的根目录查找路由.
- 如果第一段以./开头,或不以斜杠开头,则路由器将查找当前段的子段 激活的路线.
- 如果第一段以../开头,则路由器将上升一个级别.
- If the first segment begins with /, the router will look up the route from the root of the app.
- If the first segment begins with ./, or doesn't begin with a slash, the router will instead look in the children of the current activated route.
- And if the first segment begins with ../, the router will go up one level.
这篇关于routerLink绝对网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!