问题描述:

Using Express 4 and the "router" middleware

In app.js i have the following:

var subpage = require('./routes/subpage');

var app = express();

app.use('/subpage', subpage);

in subpage.js:

var express = require('express');

var router = express.Router();

router.get('/', function(req, res) {

res.render('subpage', {

title: 'Subpage'

});

});

and in subpage.jade:

block content

h1= title

p Welcome to #{title}

a(href='/todo') Todo

Is there any way I can make the subpage.jade - href render with "subpage/todo" without changing actual href it self. I have lot of hrefs in my templates, and I do not want to change these for every time I use the "subpage" in a project!?

网友答案:
var express = require('express');
var router = express.Router();

router.get('/', function(req, res) {
    res.render('subpage', {
  title: 'Subpage',
  path: 'subpage'
    });
});

and in subpage.jade:

block content
   h1= title
   p Welcome to #{title}
   a(href='/#{path}/todo') Todo
相关阅读:
Top