简体   繁体   English

无法在 angular 中使用 $location 服务更改 URL 路径

[英]Not able to change URL path using $location service in angular

I am trying to change the entire url path using $location.url service, but it's not updating the path correctly.我正在尝试使用 $location.url 服务更改整个 url 路径,但它没有正确更新路径。

Eg my path is例如我的路径是

http://localhost:64621/module/commercial/#/company/98163780-4fa6-426f-8753-e05a67d48e54

and I want to change it to the我想把它改成

http://localhost:64621/module/sales/#/sales-company/98163780-4fa6-426f-8753-e05a67d48e54

my $location.url code is我的 $location.url 代码是

$location.url('/module/sales/#/sales-company/98163780-4fa6-426f-8753-e05a67d48e54')

but still it's not properly working, it's not redirecting in the right way, please let me know how i can achieve above functionality using $location service.但它仍然不能正常工作,它没有以正确的方式重定向,请告诉我如何使用 $location 服务实现上述功能。

You should use $window.location.href for that, see documentation您应该为此使用$window.location.href ,请参阅文档

What does it not do?它不做什么?
It does not cause a full page reload when the browser URL is changed.当浏览器 URL 更改时,它不会导致整个页面重新加载。 To reload the page after changing the URL, use the lower-level API, $window.location.href.要在更改 URL 后重新加载页面,请使用较低级别的 API,$window.location.href。

you can use $location.path() to change your url您可以使用$location.path()来更改您的网址

like:喜欢:

$location.path('/module/sales/#/sales-company/98163780-4fa6-426f-8753-e05a67d48e54');

you should enable HTML5 mode你应该启用 HTML5 模式

$locationProvider.html5Mode(true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM