[英]Angular UI router request URL
I have an Angular APP using UI Router. 我有一个使用UI Router的Angular APP。
.config(function($stateProvider) {
$stateProvider
.state('blog', {
url: '/blog',
templateUrl: 'assets/javascript/blog/blog.html',
controller: 'BlogCtrl',
controllerAs: 'vm'
})
});
If I press a link with ui-sref="blog"
, the app load the blog view, but If I open in a new tab myapp/blog , it trows me 404 error. 如果我按下带有
ui-sref="blog"
的链接,则该应用程序将加载博客视图,但是如果我在新标签myapp / blog中打开,则会引发404错误。
Ps. PS。 I'm using HTML5 mode to remove the /#/
我正在使用HTML5模式删除/#/
Update: 更新:
I have separate file for each route, in app.js I use 我在app.js中使用的每条路线都有单独的文件
.config(function($stateProvider, $urlRouterProvider, $locationProvider) {
$urlRouterProvider.otherwise('home');
$locationProvider.html5Mode(true);
});
And have the <base href="/">
in the <head />
并在
<head />
包含<base href="/">
<head />
I'm doing something wrong? 我做错了吗? Can someone please explain?
有人可以解释一下吗?
For this to work on refresh/reload you need to properly set up a .htaccess file or similiar in your root and enable rewrite engine. 要使此功能在刷新/重新加载上起作用,您需要在根目录中正确设置一个.htaccess文件或类似文件并启用重写引擎。
Something like this should work. 这样的事情应该起作用。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.