Angularjs 角度ui路由器,html5模式总是刷新到/
我试图在angular中使用HTML5模式,这样我就可以为一个页面添加书签,比如http:/myhost/products(其中/products是由$stateProviderRef.state(xxx)定义的路由) 为此,我已经Angularjs 角度ui路由器,html5模式总是刷新到/,angularjs,node.js,express,angular-ui-router,Angularjs,Node.js,Express,Angular Ui Router,我试图在angular中使用HTML5模式,这样我就可以为一个页面添加书签,比如http:/myhost/products(其中/products是由$stateProviderRef.state(xxx)定义的路由) 为此,我已经 在我的应用程序配置中添加了$locationProvider.html5Mode(true) 将“base href=“/”(带)添加到my index.html 在node.js中将catch all重写添加到my server.js app.get('*',函
- 在我的应用程序配置中添加了$locationProvider.html5Mode(true)
- 将“base href=“/”(带)添加到my index.html
- 在node.js中将catch all重写添加到my server.js app.get('*',函数(req,res){ res.redirect('/'); });
- 重新启动节点服务器
谢谢您不应该像那样在服务器中重定向
app.get('*', function(req, res) { res.redirect('/'); });
而是发送相同的index.html
app.route('/*')
.get(function(req, res) {
res.sendFile(path.resolve(app.get('appPath') + '/index.html'));
});
更多信息,请查看此生成器