Angularjs ui.router不工作。不知道发生了什么事
我正在尝试用ui路由器替换ngRoute,以便可以使用多个视图 在我的模板文件中,我有Angularjs ui.router不工作。不知道发生了什么事,angularjs,angular-ui,Angularjs,Angular Ui,我正在尝试用ui路由器替换ngRoute,以便可以使用多个视图 在我的模板文件中,我有 然后在我的应用程序文件中 angular.module('myApp', [ 'ui.router', //'signup', 'myApp.controllers', 'myApp.filters', 'myApp.services', 'myApp.directives' ]).config(function($stateProvider, $urlRout
然后在我的应用程序文件中
angular.module('myApp', [
'ui.router',
//'signup',
'myApp.controllers',
'myApp.filters',
'myApp.services',
'myApp.directives'
]).config(function($stateProvider, $urlRouterProvider, $locationProvider) {
$urlRouterProvider.otherwise({
redirectTo: '/'
});
$stateProvider.
state('/', {
url: '/',
templateUrl: '/partials/homepage',
controller: 'MyCtrl1'
}).
state('about.detail', {
url: '/about/:id',
templateUrl: function(params){
return '/partials/about/'+params.id
},
controller: 'MyCtrl1'
}).
state('funnel', {
url: '/funnel',
templateUrl: '/partials/funnel',
controller: 'MyCtrl2'
});
$locationProvider.html5Mode(true);
});
由于某些原因,如果我像/漏斗一样直接前往这些路线,这些路线就不会被接受
如果我转到localhost:3000/漏斗,我是否有权选择路由?因为您使用的是HTML5模式,而不是散列,您需要在.htaccess中添加重定向以将所有内容发送回root index.html。如果没有它,您将试图找到一个不存在的目录。以下是我使用的:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^(/index\.php|/img|/js|/css|/robots\.txt|/favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
我正在使用一个节点和express后端。没有索引文件,我应该从3000中获取。这篇博文似乎可以回答你的问题,但我还没有测试过,所以我不会将其添加为答案: