routerLink 绝对 url [英] routerLink absolute url
问题描述
来自 angular 文档:><块引用>
路由器链接指令总是将提供的输入视为增量到当前网址.
例如,如果当前 url 是 /user/(box//aux:team)
.那么以下链接 <a [routerLink]="['/user/jim']">Jim</a>
将生成链接 /user/(jim//aux:team)
.
那么你如何创建一个指向 /user/jim
的链接?
我试过 ['/user/jim', { outlet: { aux: null }}]
但这不起作用.
即使它有效,它也不是最佳解决方案.我宁愿寻找一种导航到绝对网址的方法,而不是取消可能的网点.
在同一主题上,我有一个指向根的链接:routerLink="/"
就是这样做的,它重定向到我的应用程序的根,没有任何出口,如绝对链接.有趣的是,我并不特别想要那个特定链接的行为,保持任何出口路线都很好......
截至 2018 年 8 月,Angular 文档说:
<块引用>- 如果第一段以/开头,路由器将从应用的根目录查找路由.
- 如果第一段以 ./开头,或者不以斜杠开头,路由器将改为查看当前段的子段激活的路线.
- 如果第一段以 ../开头,路由器将上升一级.
From angular docs :
The router link directive always treats the provided input as a delta to the current url.
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)
.
So how do you create a link to /user/jim
?
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.
EDIT:
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...
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 绝对 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!