简体   繁体   中英

Page redirection not working with AngularJS

I am using angularjs routing in my web app, and I have included the $locationProvider and the base tag in HTML head which is <base href="/webapp/"> in order to remove the hash symbol in the URL, it works fine when I redirect using anchor tags eg <a href="/webapp/home">Home</a> but gives a 404 error when I redirect using javascript eg window.location.href = '/webapp/home'; . Tried everything but so far nothing, any help will be highly appreciated. Thank you in advance.

Try : <a href="#/webapp/home">Home</a>

When you are using angular(JavaScript) routing; JavaScript routing start after # keyword in URL, other wise browser think this is the server side routing trigger; or page will get refresh.

USE : <a href="#/webapp/home">Home</a>

$locationProvider will remove the # after redirecting to the the view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM