[英]ExpressJS/AngularJS views routing
There is some AngularJS routing: 有一些AngularJS路由:
app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider', function($stateProvider, $urlRouterProvider, $locationProvider) {
$stateProvider
.state('home', {
url: '/home',
templateUrl: '/home.html',
controller: 'MainCtrl',
resolve: {
postPromise: ['posts', function(posts){
return posts.getAll();
}]
}
})
$locationProvider.html5Mode(true)
$urlRouterProvider.otherwise('home');
}]);
This routing is at 'root/public/javascripts/app.js'. 此路由位于“ root / public / javascripts / app.js”。 So, I store home.html 'root/views/home.js'. 因此,我存储了home.html'root / views / home.js'。
My ExpressJS app file contains this string: 我的ExpressJS应用程序文件包含以下字符串:
app.set('views', path.join(__dirname, 'views'));
But when I execute my application I get error: 404 for '/home.html'. 但是,当我执行我的应用程序时,出现错误:'/home.html'的404。 How can I fix it? 我该如何解决? Thanks in advance! 提前致谢!
TemplateUrl is an Angular template that should be located in your public folder. TemplateUrl是一个Angular模板,应该位于您的公用文件夹中。 So templateUrl /home.html
will resolve to /root/public/home.html
, not /root/views/home.html
. 因此templateUrl /home.html
将解析为/root/public/home.html
,而不是/root/views/home.html
。 I feel that's where the problem is, given the info you provided. 鉴于您提供的信息,我认为这就是问题所在。
I think you should replace templateUrl: '/home.html'
with templateUrl: 'views/home.html'
(or maybe /views/home.html
). 我认为您应该将templateUrl: '/home.html'
templateUrl: 'views/home.html'
替换为templateUrl: 'views/home.html'
(或者也许是/views/home.html
)。 Currently it is not taking the home.html
in the views folder. 目前,它没有在views文件夹中使用home.html
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.