2016-01-16 47 views
1

我在鏈接我的頁面上的css/js時遇到問題。 鏈接上localhost:5000/books/1不工作 但頁面localhost:5000/books/工作node.js(express)鏈接css/js

app.use(express.static(__dirname + "/public")); 

bookRouter.route('/') 
      .get(function(req,res){ 
    res.render('books',{title:"Tytuł", nav:[ 
          { 
           Link: "/Books", 
           Text: "Books" 
          },{ 
           Link: "/Authors", 
           Text: "Authors" 
          }], 
          books: books 
         }); 


}); 

bookRouter.route('/:id') 
      .get(function(req,res){ 

     var id = req.params.id; 
     res.render('bookView',{title:"Tytuł", nav:[ 
          { 
           Link: "/Books", 
           Text: "Books" 
          },{ 
           Link: "/Authors", 
           Text: "Authors" 
          }], 
          book: books[id] 
         }); 


}); 

app.use('/books',bookRouter); 

路線上工作而不是鏈接的CSS/JSS。它在尋找http://localhost:5000/books/lib/bootstrap/dist/css/bootstrap.min.css

+0

請張貼路由'/ books /:id'的代碼... –

回答

1

你可能解決的css文件是這樣的:

<link rel="stylesheet" type="text/css" href="/lib/bootstrap/dist/css/bootstrap.min.css"> 

,如果你想了解更多關於絕對和相對看看this question

<link rel="stylesheet" type="text/css" href="lib/bootstrap/dist/css/bootstrap.min.css"> 

通過將其更換pathes。

+0

爲什麼href =「/ books /我沒有dir書?現在看書/ books/lib – wroe12

+0

public => css, lib,js – wroe12

+0

是的,我有這個文件夾 – wroe12