简体   繁体   English

页面重定向不适用于AngularJS

[英]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'; 我在我的Web应用程序中使用angularjs路由,并且在HTML头中包含$ locationProvider和base标签,它是<base href="/webapp/"> ,以便删除URL中的哈希符号,它工作正常当我使用锚标记(例如<a href="/webapp/home">Home</a>重定向时,但是在我使用javascript(例如window.location.href = '/webapp/home';重定向时却出现404错误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> 尝试<a href="#/webapp/home">Home</a>

When you are using angular(JavaScript) routing; 当您使用angular(JavaScript)路由时; JavaScript routing start after # keyword in URL, other wise browser think this is the server side routing trigger; JavaScript路由在URL中的#关键字之后开始,其他明智的浏览器认为这是服务器端路由触发器; or page will get refresh. 或页面将刷新。

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

$locationProvider will remove the # after redirecting to the the view. $ locationProvider将在重定向到视图后删除#

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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