Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS - How to read URL parameter from clean URL in non single page app

I'm currently working on a large refactoring project where my team is replacing old functionality in an application with more modern approach.

We are moving towards a single page application approach, but before we get there, we are replacing single independent web pages with AngularJS functionality.

Our backend is ASP.NET MVC application and I'm forced to use whatever I currently have; thus the URL's and such need to stay in given format:

http://example.com/controller/action/id

How can I read URL parts in my AngularJS controller, without using the so called hash-style URL's that AngularJS single page apps mostly use?

For example; I go to /user/edit/1 and need to get that id of '1' in my AngularJS controller somehow.

Any help would be greatly appreciated!

like image 574
veturi Avatar asked Dec 06 '25 19:12

veturi


1 Answers

The $location service can help you here. As per documentation https://code.angularjs.org/1.2.15/docs/guide/$location

$location service provides getter methods for read-only parts of the URL (absUrl, protocol, host, port) and getter / setter methods for url, path, search, hash:

like image 118
Chandermani Avatar answered Dec 08 '25 07:12

Chandermani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!