Showing
3 changed files
with
15 additions
and
10 deletions
@@ -19,16 +19,19 @@ const co = require('bluebird').coroutine; | @@ -19,16 +19,19 @@ const co = require('bluebird').coroutine; | ||
19 | 19 | ||
20 | const shop = { | 20 | const shop = { |
21 | 21 | ||
22 | - rewrite(req, res, next) { | ||
23 | - let pathParams = _.last(_.split(req.url.replace('.html', ''), '/')); | ||
24 | - let shopId = _.last(_.split(pathParams, '-')); | ||
25 | - | ||
26 | - if (_.isNumber(+shopId)) { | ||
27 | - req.query.shop_id = shopId; | ||
28 | - } | 22 | + onlyDomain(req, res, next) { |
23 | + req.query.domain = req.params.domain; | ||
24 | + shop.entry(req, res, next); | ||
25 | + }, | ||
29 | 26 | ||
30 | - req.query.domain = pathParams.replace(`-${shopId}`, ''); | 27 | + onlyShopId(req, res, next) { |
28 | + req.query.shop_id = req.params[0]; | ||
29 | + shop.entry(req, res, next); | ||
30 | + }, | ||
31 | 31 | ||
32 | + rewrite(req, res, next) { | ||
33 | + req.query.domain = req.params.domain; | ||
34 | + req.query.shop_id = req.params.shop_id; | ||
32 | shop.entry(req, res, next); | 35 | shop.entry(req, res, next); |
33 | }, | 36 | }, |
34 | 37 |
@@ -168,7 +168,9 @@ router.get('/index/getBrandCouponsList', list.getBrandCouponsList); | @@ -168,7 +168,9 @@ router.get('/index/getBrandCouponsList', list.getBrandCouponsList); | ||
168 | 168 | ||
169 | // 店铺重构 | 169 | // 店铺重构 |
170 | router.get('/shop', newShop.entry); // 统一店铺入口 | 170 | router.get('/shop', newShop.entry); // 统一店铺入口 |
171 | -router.get('/shop/*', newShop.rewrite); // 统一店铺入口 | 171 | +router.get('/shop/:domain/:shop_id.html', newShop.rewrite); // 域名和店铺 ID 均存在 |
172 | +router.get(/^\/shop\/(\d+)\.html/, newShop.onlyShopId); // 只有店铺 ID 的情况 | ||
173 | +router.get('/shop/:domain.html', newShop.onlyDomain); // 只有域名的情况 | ||
172 | router.get('/index/brand', newShop.entry); // 旧的路由,走到新的 controller | 174 | router.get('/index/brand', newShop.entry); // 旧的路由,走到新的 controller |
173 | router.get('/index/brandFav', newShop.brandFav); | 175 | router.get('/index/brandFav', newShop.brandFav); |
174 | router.get('/new/shop/hotlist', newShop.shopHotList); | 176 | router.get('/new/shop/hotlist', newShop.shopHotList); |
@@ -74,7 +74,7 @@ module.exports = () => { | @@ -74,7 +74,7 @@ module.exports = () => { | ||
74 | if (/^\/product\/shop/.test(req.url)) { | 74 | if (/^\/product\/shop/.test(req.url)) { |
75 | // 老路由 301 跳转到新路由 | 75 | // 老路由 301 跳转到新路由 |
76 | if (req.query.shop_id && req.query.domain) { | 76 | if (req.query.shop_id && req.query.domain) { |
77 | - return res.redirect(301, `/shop/${req.query.domain}-${req.query.shop_id}.html`); | 77 | + return res.redirect(301, `/shop/${req.query.domain}/${req.query.shop_id}.html`); |
78 | } | 78 | } |
79 | 79 | ||
80 | if (req.query.shop_id) { | 80 | if (req.query.shop_id) { |
-
Please register or login to post a comment