“Express Router” Kod odpowiedzi

Express Cierrect

app.get('/', (req, res) => {
  res.redirect('/foo/bar');
});
garzj

Ekspresowy plik routera

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

// middleware that is specific to this router
router.use(function timeLog (req, res, next) {
  console.log('Time: ', Date.now());
  next();
});
// define the home page route
router.get('/', function (req, res) {
  res.send('Birds home page');
});
// define the about route
router.get('/about', function (req, res) {
  res.send('About birds');
});

module.exports = router;
Lively Loris

Wyraź parametry trasy

Route path: /flights/:from-:to
Request URL: http://localhost:3000/flights/LAX-SFO
req.params: { "from": "LAX", "to": "SFO" }
Motionless Mouse

Express Routers

const birds = require('./birds')

// ...

app.use('/birds', birds)
ADEFOLAHAN AMORI

Express Router ()

express.Router( [options] )
Careful Cormorant

Express Router

const express = require('express')
const router = express.Router()

// middleware that is specific to this router
router.use((req, res, next) => {
  console.log('Time: ', Date.now())
  next()
})
// define the home page route
router.get('/', (req, res) => {
  res.send('Birds home page')
})
// define the about route
router.get('/about', (req, res) => {
  res.send('About birds')
})

module.exports = router
ADEFOLAHAN AMORI

Odpowiedzi podobne do “Express Router”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu