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!
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With