Jay*_*Jay 10 javascript .htaccess angularjs angular-routing
在Angular.js路由上阅读了大量的报告和stackoverflow问题之后,当我进行手动刷新时,我仍然收到"未找到"错误.
脚步:
localhost- >因为我的配置(下面),我被带到了localhost/home.视图和一切都很好.Not Found: the requested /home is not found on this server这个问题可能最像刷新页面给出"找不到页面"
我的配置
// Routing configuration.
angular.module('myModule')
.config(['$routeProvider', '$locationProvider',
function ($routeProvider, $locationProvider) {
// Enable pushState in routes.
$locationProvider.html5Mode(true);
$routeProvider
.when('/home', {
templates: {
layout: '/views/home.html'
},
title: 'Welcome!'
})
.when('/launchpad', {
templates: {
layout: '/views/layouts/default.html',
content: '/views/partials/profile.html'
},
title: "Launchpad"
})
.otherwise({
redirectTo: '/home'
});
}
]);
Run Code Online (Sandbox Code Playgroud)
我做过的其他事情:
index.html,我已经有了<base href="/">这是我尝试过的htaccess规则.没有工作.
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteCond %{REQUEST_URI} !.*\.(css|js|html|png) #Add extra extensions needed.
RewriteRule (.*) index.html [L]
</ifModule>
Run Code Online (Sandbox Code Playgroud)
来自http://ericduran.io/2013/05/31/angular-html5Mode-with-yeoman/
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /index.html/#!/$1
</IfModule>
Run Code Online (Sandbox Code Playgroud)
这个.htaccess设置对我很有用
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/$
RewriteRule (.*) /#!/$1 [NE,L,R=301]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
我不知道这是否是最佳解决方案,但我确实找到了一些有效的设置组合:
hashPrefix('!')(见下文)<base href="/">在我的index.html中FallbackResource /index.html到我的<Directory PATH_TO_WWW_FILES>服务器.conf文件中的部分.设置完成后,本地设置似乎并不重要.mod_rewrite// Routing configuration.
angular.module('myModule')
.config(['$routeProvider', '$locationProvider',
function ($routeProvider, $locationProvider) {
// Enable pushState in routes.
$locationProvider.html5Mode(true).hashPrefix('!');
$routeProvider
.when('/home', {
templates: {
layout: '/views/home.html'
},
title: 'Welcome!'
})
.when('/launchpad', {
templates: {
layout: '/views/layouts/default.html',
content: '/views/partials/profile.html'
},
title: "Launchpad"
})
.otherwise({
redirectTo: '/home'
});
}
]);
Run Code Online (Sandbox Code Playgroud)