Shivkumar
Shivkumar

Reputation: 1903

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.

E.g 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('/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.

Upvotes: 1

Views: 312

Answers (2)

Shaishab Roy
Shaishab Roy

Reputation: 16805

you can use $location.path() to change your url

like:

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

you should enable HTML5 mode

$locationProvider.html5Mode(true);

Upvotes: 0

asdf_enel_hak
asdf_enel_hak

Reputation: 7630

You should use $window.location.href for that, see documentation

What does it not do?
It does not cause a full page reload when the browser URL is changed. To reload the page after changing the URL, use the lower-level API, $window.location.href.

Upvotes: 1

Related Questions