尝试在this教程之后使用html5mode。我做过的事情 -
在app.js
$locationProvider.html5Mode(true);
index.html的head标记内。在test.com
中部署应用
<base href="/">
在apache vhost conf中重写配置。
<Directory D:/wamp/www/test.com>
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
</Directory>
完成这些步骤后,我重启了apache 结果:当我访问郊区时 -
test.com/dashboard
它正在重定向到test.com
。
test.com/#/dashboard
网址变形为test.com/#%2Fdashboard
。当我点击刷新时,它会重定向回test.com
。
路由 -
.config(['$routeProvider','$httpProvider','$locationProvider',
function($routeProvider, $httpProvider, $locationProvider) {
$tu="templates/";
$routeProvider
.when("/", { templateUrl:$tu+'home/index.html' })
.when("/dashboard", {templateUrl:$tu+'dashboard/index.html'})
.when("/notes", {templateUrl:$tu+'notes/index.html'})
$httpProvider.defaults.withCredentials = true;
$locationProvider.html5Mode(true);
}])
我也浏览过文档和其他教程,但未能使其完全正常工作/理解。请帮忙!!