ruby-on-rails – 如何在AngularJS的Rails 4中修正设置根路由?
我在使用AngularJS集成Rails路由时遇到了麻烦.
当我在浏览器输入中转到“localhost:3000”时,它会将我重定向到“localhost:3000 /#/ auth / sign_in” 但’sign_in’模板无法渲染. 然后,如果我转到“localhost:3000 /#/”,它会将我重定向到“localhost:3000 /#/ auth / sign_in”并向右渲染“sign_in”模板. 如何修复它,当我去“localhost:3000”然后渲染’sign_in’? 路由器代码在这里:http://pastie.org/8917505 谢谢! 解决方法
我找到了解决方案.
您需要为AngularJS启用HTML5模式: angular.module('app').config(['$routeProvider','$locationProvider',function ($routeProvider,$locationProvider) { ... $locationProvider.html5Mode(true); }] ) 您还需要添加< base> html标签: <html> <head> <base href="/"> ... </head> </html> 当您再次在浏览器URL输入中按Enter键时,它修复了Angular对URL路径的错误处理.如果没有这个,最后的“域名”将会重复: 本地主机:3000 / auth /中sign_in 本地主机:3000 /认证/认证/ sign_in … 您还需要在服务器端(在Rails中)为所有SPA路由编写正确的路由: 配置/ routes.rb中 root 'application#main' get '*path',to: 'application#main' (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |