本文介绍了Angular2,相对导航(向后两级../../)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序中有一个后退按钮,它可以向后导航一些级别.如果是一级
I have a back button in my application, which navigates relatively some levels back. In case of one level
this.router.navigate(['..'], { relativeTo: this.route });
它运行完美(生成的路由URL:http://localhost:3000/three/two/one
).在两级后退的情况下.导航
it works perfectly (resulted route url:http://localhost:3000/three/two/one
). In case of two level back rel. navigation
this.router.navigate(['..', '..'], { relativeTo: this.route });
router向后导航两个级别,但,生成的路由URL现在看起来像http://localhost:3000/three/two/
(斜杠,这是不正确的).
router navigates two levels back, BUT the resulted route url looks now like http://localhost:3000/three/two/
(tailing slash, which is not correct).
我做错什么了吗,或者可能是个错误?
Am I doing something wrong or could it be a bug?
推荐答案
在两个级别以下的情况下,请使用以下命令:
In case of two levels down use this:
this.router.navigate(['../../'], { relativeTo: this.route });
这篇关于Angular2,相对导航(向后两级../../)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!