Reputation: 149
code below, when I visit url like this http://localhost/
. It can match the first one, but when I visit http://localhost/detail-999
, It match the first one again. It can not match the second one.
I want that when I visit http://localhost
or http://localhost/list-1-1
can match the first one and when visit http://localhost/detail-999
can match the second one correctly...
I have no idea to fix this problem...
router.get('/|/list-:type-:page', function (req, res) {});
router.get('/detail-:itemId', function (req, res) {});
Upvotes: 0
Views: 68
Reputation: 1
Try this:
router.get('/list/:type/:page', function (req, res, next) {});
router.get('/detail/:itemId', function (req, res, next) {});
It can be problematic designing your routes as you did. If you have params that can not be changed then you should handle the dashes in the route's action method and just do a req.params.list_name.split('-')
Upvotes: 0
Reputation: 445
All you need is to wrap it to brackets like this:
app.get('(/|/list-:type-:page)', function (req, res) {
});
Upvotes: 1