我是网络前端世界的新手。我有路线:/product
,/shop
。对于每条路线,我都创建了控制器。问题是如何从/shop
页面打开/product
路由页面。当我致电res.render('product');
时,它会路由http://localhost:3000/shop/products
而不是http://localhost:3000/products
。
我该如何解决这个问题?
答案 0 :(得分:1)
您被重定向到http://localhost:3000/shop/products
,因为执行请求之前的当前路径是:http://localhost:3000/shop
要直接继续/products
,您可以执行以下操作
..
调用文件系统中的父级(使用相对路径)res.render('../products')
res.render('/products')
答案 1 :(得分:0)
使用
重定向
在您的路线中快速重定向
示例:
app.get('/shop', function(req, res) {
res.redirect('/products');
});