码迷,mamicode.com
首页 > Web开发 > 详细

node.js的路由

时间:2016-06-05 22:51:07      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

app.js:

app.use(‘/‘, routes);
app.use(‘/reg‘, routes);
app.use(‘/u/:user‘,routes);
app.use(‘/post‘,routes);
app.use(‘doReg‘,routes);
app.use(‘login‘,routes);
app.use(‘login‘,routes);
app.use(‘logout‘,routes);
app.use(‘/users‘, users);

 

routes/index.js

 

var express = require(‘express‘);
var router = express.Router();

/* GET home page. */
router.get(‘/‘, function(req, res, next) {
res.render(‘index‘, { title: ‘首页‘ });
});


router.get(‘/u/:user‘, function(req, res, next) {

});

router.post(‘/post‘, function(req, res, next) {
res.render(‘post‘, { title: ‘post‘ });
});

router.get(‘/reg‘, function(req, res, next) {
res.render(‘reg‘, { title: ‘注册页面‘ });
});

router.post(‘/doReg‘, function(req, res, next) {
res.render(‘doreg‘, { title: ‘doreg‘ });
});

router.get(‘/login‘, function(req, res, next) {
res.render(‘login‘, { title: ‘登录页面‘ });
});

router.post(‘/doLogin‘, function(req, res, next) {
res.render(‘dologin‘, { title: ‘doLogin‘ });
});

router.get(‘/logout‘, function(req, res, next) {
res.render(‘logout‘, { title: ‘logout‘ });
});


module.exports = router;

 

node.js的路由

标签:

原文地址:http://www.cnblogs.com/lgp2000/p/5561877.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!