Vietnam

    Nodejs.vn

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags
    • Groups
    • Search

    [Built-in middleware express.static] Gặp vấn đề khi tạo nhiều sub router

    ExpressJS/Conect.IO
    0
    3
    454
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      T Hưng last edited by

      Chào mọi người, em mới tập tành code NọdeJS bằng Express nhưng em gặp phải một vấn đề không biết phải xử lý sao. Hy vọng mọi người ai đã gặp qua vấn đề này có thể giúp em ạ. Khi em sub thêm một router như code bên dưới thì nó lại không load CSS lên được
      router.get('/edit', function(req, res, next) {
      res.render('admin/users/user', { title: 'Express' });
      });
      Mà toàn bộ phần CSS em đều lưu trong Public hết rồi.
      Lúc em điền url trên browser:
      http://localhost:3000/users/edit
      Phần console lúc nào nó cũng hiện:
      GET user/css/lib/bootstrap/bootstrap.min.css 304 6.437 ms - -
      mà đáng lẽ là vậy mới load được CSS
      GET /css/lib/bootstrap/bootstrap.min.css 304 6.437 ms - -

      0_1527131999241_Screen Shot 2018-05-24 at 10.19.27 AM.png

      0_1527132048063_Screen Shot 2018-05-24 at 10.20.35 AM.png

      Vũ T 2 Replies Last reply Reply Quote 0
      • Vũ
        Vũ Global Moderator @T Hưng last edited by

        @T-Hưng Nội dung trong file user.ejs bạn đang trỏ tới file css như thế nào? Bạn thử đổi lại đường dẫn tuyệt đối xem, ví dụ: /css/style.css. Chú ý là có ký tự sổ ngược / ở đằng trước.

        Tech-nông
        Email: [email protected]
        Profile: about.me/vunb
        Github: github.com/vunb
        Twitter: twitter.com/nhubaovu

        1 Reply Last reply Reply Quote 0
        • T
          T Hưng @T Hưng last edited by

          @T-Hưng Em làm được rồi anh. Em cảm ơn anh #Vũ nhiều nha.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          $(document).ready(function () { app.coldLoad(); }); }