Location service
$ is responsible for parsing the URL in the address bar of the browser and makes the URL available to your APP.
Since you use regular URLs and search segments, you need to set the $ locationProvider html5Mode parameter to true.
$ locationProvider will use hashbang as its default mode.
If you do not set html5Mode to true, you will get an empty string when trying to get the url.
Then use the $ location function to retrieve the url after installing html5Mode.
And write your own rule to handle the path.
Suppose your full URL is as follows: http://example.com/person/show/321
Main.js
angular.module("MyAPP",[],function($locationProvider){ $locationProvider.html5Mode(true); }); function MainController($location){ var pId = $location.path().split("/")[3]||"Unknown";
index.html
<!DOCTYPE html> <html lang="en" ng-app="MyAPP"> <head> <meta charset="utf-8"> <title>Angular test</title> </head> <body ng-controller="MainController"> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script> <script src="js/main.js"></script> </body> </html>
Hope this helps you.
source share