2016-02-28 154 views
0

我有這個快速的應用程序,利用路線和hbs進行思考。當我添加子路線(如\risi\first)時,所有css/html文件的路徑名稱都附加了路由名稱 - risiNodejs/Express.js路徑問題

如何讓它們訪問文件?

從app.js相關代碼:

var risi= require('./routes/risi'); 
app.use('/risi', risi); 

Risi.js路線:

var express = require('express'); 

var router = express.Router(); 

router.get('/', function(req, res, next) { 
    res.render('risi', { title: 'RISI' }); //Works perfectly fine 
}); 

router.get('/first', function(req, res, next) { 
    res.render('risi', { title: 'RISI' }); //unable to access the CSS/JS from here 
}); 

router.get('/second', function(req, res, next) { 
    res.render('risi', { title: 'Joi' }); 
}); 

router.get('/third', function(req, res, next) { 
    res.render('risi', { title: 'Log' }); 
}); 

router.get('/fourth', function(req, res, next) { 
    res.render('risi', { title: 'Yo TO RISI!! <3' }); 
}); 

module.exports = router; 

下面是從控制檯的錯誤:

GET /risi/css/main.css 404 99.4567 ms -1166

的說CSS文件在/css/main.css

有人請求hlp!

+1

哪裏HTML您應該使用絕對路徑

/css/main.css 

(注意預謀/)鏈接到你的CSS文件,以保證在href不附加?你的鏈接是css'css/main.css'還是'/ css/main.css'? – baao

+0

其'css/main.css' – QuikProBroNa

回答