lundi 2 novembre 2015

Jade path resolution for expressjs

Background info: I am working on a web app for express. Currently, I have all views in one directory. I would like to structure my views folder to contain multiple directories to group views together. The problem is that when I do that my paths get messed up. For example, if I have a dir structure like:

views
->photos
-->search.jade
-->stats.jade

and if I click the stats link first, then search link, I will get an error saying that it could not find 'photos/photos/search'. I think it has something to do with the fact that I loaded stats from the photos directory and it somehow tacks on the extra photos to the dir path since the hrefs are relative I think. I read around in the API docs and online with no information. Can someone shed some light on this?

doctype html
html(lang='en')
  head
    link(rel='stylesheet', href='/css/style.css')
    block header
  body
    // Navigation
    nav.navbar.navbar-inverse.navbar-fixed-top(role='navigation')
      .container
        // Brand and toggle get grouped for better mobile display
        .navbar-header
          button.navbar-toggle(type='button', data-toggle='collapse', data-target='socialid-nav')
            span.sr-only Toggle navigation
            span.icon-bar
            span.icon-bar
            span.icon-bar
          a.navbar-brand(href='#') HOME
        // Collect the nav links, forms, and other content for toggling
        .collapse.navbar-collapse(id='app-nav')
          ul.nav.navbar-nav
            li
              a(href='/home') Home
            if user
                li
                  a(href='photos/search') Search
                li
                  a(href='photos/stats') Stats
                li
                  a(href='/logs') Search Logs
                li
                  a(href='#') Logged in as: #{user.username}(#{userRole})            
                li
                  a(href='/signout') Sign Out
        // /.navbar-collapse
      // /.container
    // Page Content
    block content

    // Footer
    footer
      .row
        .col-lg-12
          p Copyright © SOCIAL-ID 2014

    block scripts




Aucun commentaire:

Enregistrer un commentaire