[英]Going back to previews page on Angular
I have a button that should take the user to the previews page.我有一个按钮可以将用户带到预览页面。
I'm at #/country/2
- 2 being an idx
When I click the button below it sends me to: #/country/2/brands
, when it should be #/brands
我在#/country/2
- 2 是一个idx
当我单击下面的按钮时,它会将我发送到: #/country/2/brands
,当它应该是#/brands
<a [routerLink]="['brands']"><input value="sub" type="submit"></a>
I have imported router
and ActivatedRoute
.我已经导入了router
和ActivatedRoute
。 I have more routes working but not this one.我有更多路线可用,但没有这条路线。 Any suggestion will be welcomed.任何建议都将受到欢迎。
What's happening right now is that it's accessing relative path.现在发生的是它正在访问相对路径。 Since you are at #/country/2/
, with ['brand']
, you will definitely be directed to #/country/2/brands
and that is the expected behavior of your code.由于您在#/country/2/
,使用['brand']
,您肯定会被定向到#/country/2/brands
,这是您的代码的预期行为。
Here's a very good explanation of the different routerLink parameter formats: routerLink absolute url这里对不同的routerLink参数格式进行了很好的解释: routerLink absolute url
If #/brands
is from the root of your application, you simply need to use:如果#/brands
来自应用程序的根目录,则只需使用:
<a [routerLink]="['/brands']"><input value="sub" type="submit"></a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.