vendredi 24 février 2017

my route do not work ,use express and ejs

i want to click link to solution page,but my route don't work,what's wrong?

  1. app.js

    var express = require('express'); var path = require('path'); var
    favicon = require('serve-favicon'); var logger=require('morgan');
    var cookieParser = require('cookie-parser'); var bodyParser =
    require('body-parser'); var expressLayouts =
    require('express-ejs-layouts');
    
    var index = require('./routes/index'); var users =
    require('./routes/users');
    
    var app = express();
    
    app.set('layout', 'layout/layout'); app.set('view engine', 'ejs');
    
    app.use(expressLayouts);
    app.use(logger('dev')); app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: false }));
    app.use(cookieParser()); app.use(express.static(path.joindirname,
    'public')));
    
    app.use('/', index); app.use('/users', users); app.use('/solution',
    index);
    
    

    2.routes/index var express = require('express'); var router = express.Router();

    router.get('/', function(req, res) {
         res.render('pages/index'});
    });
    
    router.get('/solution', function(req, res) {
         res.render('pages/solution');
    });
    
    module.exports = router;
    
    



Aucun commentaire:

Enregistrer un commentaire