/category/fruit/apple说,我有一个有多个路由的角度项目,所以完整的url是http://myserver/category/fruit/apple,通过路由器链接,一切都很好,但是如果我在输入URL时直接打开这个链接,那么就是404,我的后端是带有404的nodejs。而404是有意义的,因为没有像这样配置的路由。
我的问题,在这种情况下我该怎么办?
我想我有,重定向到根http://myserver?path=category-fruit-apple,并从根组件进行动态路由。这是正确的方式吗?
请推荐最好的方法。
发布于 2019-09-19 08:06:03
在nodejs中使用index.html返回
// Redirect all the other requests
this.app.get('*', (req: Request, res: Response) => {
if (allowedExt.filter((ext) => req.url.indexOf(ext) > 0).length > 0) {
res.sendFile(path.resolve(`dist/assets/${req.url.split('?')[0]}`));
} else {
res.sendFile(path.resolve('dist/app/index.html'));
}
});https://stackoverflow.com/questions/57918153
复制相似问题