我正在做一个样本MEAN应用程序。我有我的角度路由,但当我提出任何请求时,它直接命中服务器并给我一个无法获取/电影。
以下是我提供静态文件的服务器端代码。
//Serve html files
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html');
});
//Register all the client folder
var client = __dirname + '/modules';
fs.readdir(client, function(err,files) {
files.map(function(file){
app.use(express.static(path.join(__dirname, '/modules'+'/'+file+'/client')));
})
});
//Serve js files
app.use(express.static(path.join(__dirname, '/public')));
//Load the models
app.models = require('./index');
//Load the routes
var routes = require('./routes');
_.each(routes,function(controller,route){
app.use(route,controller(app,route));
});
在我的客户端文件夹中,另一个名为“view”的文件夹就在那里我的所有模板都在那里。
以下是我/电影网址的路由
angular.module('movies').config(['$stateProvider',
function ($stateProvider) {
// Movies state routing
$stateProvider
.state('movies.list', {
url: '/movies',
templateUrl: 'views/movie.html'
})
}
]);
答案 0 :(得分:0)
将urlRouterProvider
添加到配置并将控制器添加到stateProvider.state
:
myApp.config(function($stateProvider, $urlRouterProvider) {
//
// For any unmatched url, redirect to /state1
$urlRouterProvider.otherwise("/state1");
//
// Now set up the states
$stateProvider
.state('state1.list', {
url: "/list",
templateUrl: "partials/state1.list.html",
controller: function($scope) {
$scope.items = ["A", "List", "Of", "Items"];
}
})
});
答案 1 :(得分:0)
通过使用州名.state('movies.list', {
中的点,您将创建父状态“电影”的嵌套状态“列表”。
如果您不希望创建嵌套状态,请删除该点并将其命名为“listMovies”,它应该可以正常工作。
<强>更新强>
在您的快速配置中:
app.get('/*', function(req, res) {
res.sendFile(__dirname + '/index.html')
});
并且在您的角度路线中:
angular.module('movies').config(['$stateProvider', '$locationProvider',
function ($stateProvider, $locationProvider) {
// Movies state routing
$stateProvider
.state('movies', {
url: '/movies',
templateUrl: 'views/movie.html'
});
$locationProvider.html5Mode(true);
}
]);