angular 6 如何将 url 相对地作为字符串

angular 6 How do I get url relatively as string

我有当前页面的url字符串

使用_router.url

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

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

> localhost:4200/School/12300

我怎样才能简单地做到这一点? (没有 split 和 foreach 函数)

最后,我意识到我可以使用像 "../../"

这样的相对路径

即使我没有完整路径,这也总是有效。

谢谢!