Specific writing examples:
1.js defines a controller
function MyCtrl($scope, $location) { $scope.jumpToUrl = function(path) { //TODO:add code here };}2. Apply controller in html
<div ng-controller='MyCtrl'> <button ng-click="jumpToUrl('/signin')">signin</button></div>3.Fill in the TODO position in the controller
$location.path(path);
Then run it to see the effect.
Suppose the url of the current page is: http://127.0.0.1:8080/#/home
$location.path(path); After execution, it will jump to http://127.0.0.1:8080/#/signin
If you find that the page cannot redirect normally, you can add a sentence after $location.path(path);
var curUrl = $location.absUrl(); // Used to display the full path of the url
When debugging the tracking page, you can probably guess what the curUrl value becomes.
OK, the above is all about using Controller to complete URL redirection in AngularJS. I hope this article will be helpful to everyone to learn AngularJS.