[英]$locationProvider html5mode causing “cannot GET” error on refresh - AngularJS Node app
[英]Throwing cannot get error after enabling html5Mode in AngularJS
我在我的应用程序中使用UI-Router进行路由/状态,并且URL有“#”所以要删除它,我使用$locationProvider
类的 -
function configState($stateProvider, $urlRouterProvider, $locationProvider) {
$locationProvider.html5Mode(true);
在模块依赖ngRoute
中添加了ngRoute
,并在index.html中添加了<base href="/" >
。
问题 -
如果我使用这就像在同一个标签一个正常的应用程序,并导航到其他国家,它的工作原理, 但每当我在另一个标签粘贴网址并回车其投掷Cannot GET /app_views/contacts
网址就像是- http://localhost:9000/app_views/contacts
虽然在URL中使用哈希,但它以两种方式工作。
您可能会收到此错误,因为您的服务器配置不正确。 换句话说,当您手动输入/app_views/contacts
,它将向服务器请求该页面。 为了使其正常工作,您需要配置服务器以将所有流量路由到index.html
页面,以便Angular正确接管并显示正确的视图。
这是一个相关的帖子重新加载页面给出了AngularJS HTML5模式的错误GET请求
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.