SoFunction
Updated on 2025-04-12

AngularJS uses Controller to complete URL jump

Specific writing examples:

Define a controller

function MyCtrl($scope, $location) {

  $ = function(path) {

    //TODO:add code here

  };

}

Apply controller inside

<div ng-controller=‘MyCtrl'>

  <button ng-click="jumpToUrl('/signin')">signin</button>

</div>

Fill in the TODO position

$(path);

Then run it to see the effect.

Suppose the url of the current page is: http://127.0.0.1:8080/#/home

$(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$(path);Add another sentence later

var curUrl = $(); //Used to displayurlFull path

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.