javascript 如何在 AngularJS 中使用带有 $location.path() 的查询字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24188562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 02:19:43  来源:igfitidea点击:

How to use Querystring with $location.path() in AngularJS

javascriptangularjs

提问by aikutto

I want to redirect user to another page after successful login using query string. If I copy & paste to browser's address bar http://example.com/#/login?ref=/path/to/redirectit works fine. But if I use

我想在使用查询字符串成功登录后将用户重定向到另一个页面。如果我复制并粘贴到浏览器的地址栏,http://example.com/#/login?ref=/path/to/redirect它工作正常。但如果我使用

$location.path("/login?ref=/path/to/redirect");

url looks like

网址看起来像

http://example.com/#/login%3Fref=/path/to/redirect

How can I decode %3F to '?' ? Thanks

如何将 %3F 解码为“?” ? 谢谢

回答by Stepan Suvorov

It should be

它应该是

$location.path('/login').search('ref', '/path/to/redirect')

回答by pykiss

I had the same problem.

我有同样的问题。

I want to change path and search the same time.

我想同时更改路径和搜索。

It is possible by doing this:

这样做是可能的:

$location.$$search ={foo:'bar', buz:'buz'}
$location.$$path = '/some/path'
$location.$$compose()

It is not documented and it could broke at any new angular version.

它没有记录,它可能会在任何新的角度版本中崩溃。