相关疑难解决方法(0)

Angular和Express路由

我经历过许多Angular-express种子,并且研究了它们的工作方式.我遇到的问题是:1).我想用ejs-locals进行模板化.2).如何正确配置服务器端和客户端的路由.而且,在输入URL时/about,不要生成错误:cannot /get

angular app.js包含:

// angular stuff

$routeprovider.when('/', {
 templateUrl: 'index',
 controller: IndexCtrl
});
$routeprovider.when('/about', {
 templateUrl: 'partials/about',
 controller: IndexCtrl
});
Run Code Online (Sandbox Code Playgroud)

快递app,js包含:

app.get('/', routes.index);
app.get('/about', routes.about);
Run Code Online (Sandbox Code Playgroud)

routes文件夹包含'index.js':

exports.index = function(req, res){
  res.render('index',{name:"Hello"});
};

exports.about = function (req, res) {
  res.render('partials/about');
};
Run Code Online (Sandbox Code Playgroud)

Views文件夹包含index.ejs:

<!--HTML head/navigation bar here-->
<div ng-view></div>
Run Code Online (Sandbox Code Playgroud)

和inside views文件夹是一个partials文件夹:(Views/partials /)

index.ejs:

 <h1>Index</h1>
Run Code Online (Sandbox Code Playgroud)

about.ejs:

<h1>About</h1>
Run Code Online (Sandbox Code Playgroud)

express angularjs

40
推荐指数
3
解决办法
2万
查看次数

标签 统计

angularjs ×1

express ×1