title: how to load assets in ejs file when you have two different main routes?
body: <p>i have simple blog express app which i set up of two different main routes, regular routes (login,post,signup etc...) and for admin (add post,edit post etc...) the issue is my assets, css or any other static files does not load in the <strong>admin routes</strong> only but fortunately works in regular routes. my express setup is as follow:</p>
  
  <pre><code>app.use('/admin/pages', adminPages);
  app.use('/', pages);
  </code></pre>
  
  <p>so after investigating the chrome developer tools for both main routs this is the issue but have no idea how to solve it ! 
  this is when the admin routs does not load bootstrap or css files:
  <a href="https://i.stack.imgur.com/pSiUc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pSiUc.png" alt="enter image description here"></a>
  notice all assets is prefixed with unwanted (admin/pages/...) after localhost:3005</p>
  
  <p>but it works here (without the prefix) :
  <a href="https://i.stack.imgur.com/q5kWv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q5kWv.png" alt="enter image description here"></a></p>
  
  <p>heres my file structure:</p>
  
  <p><a href="https://i.stack.imgur.com/Mn5Tc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mn5Tc.png" alt="enter image description here"></a></p>
  
  <p>full App.js :</p>
  
  <pre><code>const express = require('express'),
      app = express(),
      path = require('path'),
      mongoose = require('mongoose'),
      bodyParser = require('body-parser'),
      pages = require('./routes/pages.js'),
      config = require('./config/database'),
      expressSession = require('express-session'),
      expressValidator = require('express-validator'),
      adminPages = require('./routes/admin_pages.js');
  
  mongoose.connect(config.database);
  const database = mongoose.connection;
  database.on('error', console.error.bind(console, '@@error with database:'));
  database.once('open', () =&gt; {
      console.log('Connected To Database successfully');
  });
  
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'ejs');
  app.use(express.static(path.join(__dirname, 'public')));
  // app.use(express.static('public'));
  
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(bodyParser.json());
  
  app.set('trust proxy', 1);
  app.use(
      expressSession({
          secret: 'keyboard cat',
          resave: false,
          saveUninitialized: true,
          cookie: { secure: true }
      })
  );
  
  app.use(require('connect-flash')());
  app.use(function(req, res, next) {
      res.locals.messages = require('express-messages')(req, res);
      next();
  });
  
  app.use(
      expressValidator({
          errorFormatter: function(param, msg, value) {
              var namespace = param.split('.'),
                  root = namespace.shift(),
                  formParam = root;
              while (namespace.length) {
                  formParam += '[' + namespace.shift() + ']';
              }
              return {
                  param: formParam,
                  msg: msg,
                  value: value
              };
          }
      })
  );
  
  app.use('/admin/pages', adminPages);
  app.use('/', pages);
  
  const port = 3005;
  app.listen(port, () =&gt; {
      console.log(`App Listening @ localhost:${port}`);
  });
  </code></pre>
  
  <p>add_page.ejs :</p>
  
  <pre><code>&lt;%- include('../_layouts/header') %&gt;
  
      &lt;form&gt;
          &lt;input type="text" /&gt;
          &lt;input type="text" /&gt;
          &lt;input type="text" /&gt;
          &lt;button&gt; submit &lt;/button&gt;
      &lt;/form&gt;
      &lt;%- include('../_layouts/footer') %&gt;
  </code></pre>
  
  <p>heres my both main routes:
  <a href="https://i.stack.imgur.com/8UR06.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8UR06.png" alt="enter image description here"></a></p>