2

Issue

I have an abstract route that looks like this: #/app/lists/:label.

Which is great when User creates a "label" of 'Breakfasts'.

However, when the label value is '#All', then $stateParams.label === "".

Question

How can I get Angular/-ui-router to acknowledge the octothorpe (hash sign) in the literal URL of #/app/lists/#All? ($stateParams.label)

Allowing the User to add an octothorpe, such as #All or #Public, is a necessary convention I'd like to keep for the user. What can I do to get this "label" when this character is present?

4

2 回答 2

2

您可以对该参数进行编码和解码以放置“#”。

路由到#/app/lists/:label值为“#All”的页面时

encodeURIComponent('#All');

这将返回"%23All"

并且在读取数据时,您需要在代码中对其进行解码:

decodeURIComponent("%23All");
于 2017-04-13T03:15:06.097 回答
0

我仍然是角度的菜鸟。刚看到这个问题很好奇,发现了类似的东西——Hashbang Mode。

https://docs.angularjs.org/guide/ $location

Hashbang 模式简化。

虽然我不确定这是否会对您的情况有所帮助。

于 2017-04-13T09:52:45.873 回答