1

I have problem with linking my css/js on my page. Linking on localhost:5000/books/1 not working but on the page localhost:5000/books/ working

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);

Route work but not linking css/jss. It looking in http://localhost:5000/books/lib/bootstrap/dist/css/bootstrap.min.css

1
  • Please, post the code that routes /books/:id... Commented Jan 16, 2016 at 21:20

2 Answers 2

2

I have the same problem with yours. The point is why it looks for CSS files(or js) from http://localhost:5000/books/lib/bootstrap/dist/css/bootstrap.min.css instead of from http://localhost:5000/lib/bootstrap/dist/css/bootstrap.min.css

try to add

<base href="/">

in your html files. Mines worked.

Sign up to request clarification or add additional context in comments.

Comments

1

You probably addressed the css files like this:

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

Replace it by:

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

Take a look at this question if you want to learn more about absolute and relative pathes.

5 Comments

why href="/books/ I don't have dir book ? Now it looking books/books/lib
public => css, lib, js
Yes I have this folder
where is it? Can you post the path to your bootstrap.min.css?
If you don't start the path with /, it is going to be a relative path. It means whatever the url is, it is going to append it to the url. if you start it with /, it is going to be appended to your domain, not the url. so it would work for all urls. See this answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.