路由怎么写才能让type为空时访问到默认的数据
type = ' '时:http://abc.com/user/1002
(现在的情况是,type为空时报错)
type = friend 时:http://abc.com/user/1002/friend
app.get('/user/:id/:type', function (req, res, next) {
console.log('although this matches');
next();
});
路由怎么写才能让type为空时访问到默认的数据
type = ' '时:http://abc.com/user/1002
(现在的情况是,type为空时报错)
type = friend 时:http://abc.com/user/1002/friend
app.get('/user/:id/:type', function (req, res, next) {
console.log('although this matches');
next();
});
在你的这个路由前面补一个跳转路由吧:
app.get('/user/:id', function (req, res) {
res.redirect('/user/' + req.params.id + '/默认值');
});
注意,一定要加在你的路由前面
3 回答2.7k 阅读✓ 已解决
1 回答1k 阅读✓ 已解决
1 回答1.1k 阅读✓ 已解决
2 回答1.3k 阅读
2 回答668 阅读✓ 已解决
2 回答1.7k 阅读
2 回答1.1k 阅读
type='/'