首页 > 解决方案 > angular 6 如何获取相对于字符串的 url

问题描述

我有当前页面的 url 字符串

使用_router.url

> localhost:4200/School/12300/Demography/12345

但我需要从 Demography 中删除 url 的结尾,直到结束,如:

> localhost:4200/School/12300

我怎么能简单地做到这一点?(没有 split 和 foreach 功能)

标签: angulartypescriptangular6router

解决方案


最后,我意识到我可以使用相对路径"../../"

即使我没有完整的路径,这也可以始终有效。

谢谢!


推荐阅读