快速路由附加URL而不是覆盖

时间:2016-06-15 05:08:44

标签: node.js express

修改

现在视图非常简单,因为我只是试图布局使用导航栏设置的路线...

ul.nav.in#side-menu
    li.sidebar-search
        div.input-group.custom-search-form
            input(type='text', class='form-control', placeholder='Search contacts...')
            span.input-group-btn
                button.btn.btn-default(type='button')
                    i.fa.fa-search
    li
        a(href='/')
            i.fa.fa-dashboard.fa-fw 
            &nbspDashboard
    li
        a(href='#')
            i.fa.fa-user.fa-fw 
            &nbspContacts
            span.fa.arrow
        ul.nav.nav-second-level.collapse
            li
                a(href='contacts/investors') Investors
            li
                a(href='contacts/agents') Agents

简单的问题我确定。我的主页上的链接正在追加并添加到URL而不是请求新的URL。

路由文件

var express = require('express');
var router = express.Router();
var ctrlData = require('../controllers/data')
var ctrlPageBuilder = require('../controllers/pageBuilder')

router.get('/', ctrlPageBuilder.renderHomePage);
router.get('/contacts/investors', ctrlPageBuilder.renderInvestorsPage);
router.get('/contacts/agents', ctrlPageBuilder.renderAgentsPage);
router.get('/contacts/vendors', ctrlPageBuilder.renderVendorsPage);
router.get('/properties', ctrlPageBuilder.renderPropertiesPage);

module.exports = router;

然后我的控制器

//Controllers to render pages on the browser
var baseUrl = 'http://localhost:3000'

module.exports.renderHomePage = function(req, res) {
    res.render('index', {title: 'REA Dashboard'});
};

module.exports.renderInvestorsPage = function(req, res) {
    res.render('investors', {title: 'Investors'});
};

module.exports.renderAgentsPage = function(req, res) {
    res.render('agents', {title: 'Agents'});
};

....

代码在生产环境中呈现:

On page load   : http://localhost:3000
Click Investors: http://localhost:3000/contacts/investors
Click Agents   : http://localhost:3000/contacts/contacts/agents
                    404 ERROR

0 个答案:

没有答案