nuxt2如何在nuxt.config.js中直接捕获服务端错误?-灵析社区

栀子花爷爷

// nuxt.config.js export default { serverMiddleware: [ (req, res, next) => { try { decodeURIComponent(req.url); next(); } catch (err) { if (err instanceof URIError) { req.url = '/'; // 修改req.url成一个有用的URL res.writeHead(302, { Location: '/' }); res.end(); } else { next(err); } } }, ], // ...其他配置 };

阅读量:1

点赞量:0

问AI