Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个提供文件列表的应用程序。
应用程序必须响应以下路由:
/company/:id /company/:id/dir /company/:id/dir/dir
这/company/:id是一个没有path指定的路由,例如一个root目录。我在想一些app.get('/company/:id/:path', ...显然行不通的东西。
/company/:id
path
root
app.get('/company/:id/:path', ...
如何定义响应所有示例的路由?
使用/company/:id*(注意尾随星号)。
/company/:id*
完整示例
var express = require('express')(); express.use(express.router); express.get('/company/:id*', function(req, res, next) { res.json({ id: req.params['id'], path: req.params[0] }); }); express.listen(8080);