Html5Mode - 刷新 angularjs 页面问题 [英] Html5Mode - refreshing the angularjs page issue

查看:44
本文介绍了Html5Mode - 刷新 angularjs 页面问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 angularJS 应用程序,它的 URL 格式为(在开发中)-

I am working on an angularJS app, which has URLs in the format (in dev) -

http://localhost:6001/#/home/index
http://localhost:6001/#/content/index

由于这个应用程序也可以在桌面浏览器上使用,我希望 URL 没有#",所以我在我的应用程序的配置部分添加了这个 -

As this app, will also be available on desktop browser, I wanted the URLs to be without '#', so I added this in my app's config section -

$locationProvider.html5Mode(true);

哪个工作正常并且网址不显示#".但是现在有一个问题.在浏览器中刷新特定页面时,现在出现此错误 -

Which works fine and URLs don't show '#'. But there is a problem now. On refreshing a particular page in browser, now I get this error -

Cannot GET /home/index

是否需要进行任何其他更改才能使其正常工作?

Are there any other changes required to get this working?

注意:此应用使用cordova CLI并托管​​在Node.js服务器上.

Note: This app is using cordova CLI and is hosted on a Node.js server.

推荐答案

尝试把你的作为你的路线:

Try to put in your as your route:

app.get(*, function(req,res) {
  //return the main index file
});

这将导致任何不匹配的路由为索引页面提供服务,并从那里角度处理这条路由.

This will cause any unmatched route to serve the index page and from there angular take care of this route.

这篇关于Html5Mode - 刷新 angularjs 页面问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆