Angular and Express routing

前端 未结 4 1481
日久生厌
日久生厌 2020-12-02 07:30

I\'ve been through many Angular-express seeds and kind of worked out how they work. The problem I am having is: 1). I would like to use ejs-locals for temp

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 08:05

    Add these routes to your express server

    app.get('/partials/:filename', routes.partials);
    app.use(routes.index);
    

    Then in routes.js

    exports.partials = function(req, res){
      var filename = req.params.filename;
      if(!filename) return;  // might want to change this
      res.render("partials/" + filename );
    };
    
    exports.index = function(req, res){
      res.render('index', {message:"Hello!!!"});
    };
    

    This will make sure that express returns rendered templates when making requests to partials/index and partials/about.

    Here's a gist: https://gist.github.com/4277025

提交回复
热议问题