【发布时间】:2022-01-08 13:05:01
【问题描述】:
自从我在 login.js
上尝试使用受保护的路由 <Router basepath="/">
<PrivateRoute path="/edit" />
</Router>
这在 edit.js
useEffect(() => {
// ... some code here
getEscritos();
if (!user && location.pathname !== `/login`) {
navigate("/login");
return null;
}
}, []);
我无法再构建它...错误是:
窗口未定义
虽然在本地运行良好。一切正常。
然后我在研究后在 gatsby-node.js 上尝试了这个
exports.onCreateWebpackConfig = ({ stage, loaders,
actions, getConfig }) => {
if (stage === "build-html" || stage === "develop-html") {
actions.setWebpackConfig({
module: {
rules: [
{
test: /reach-router/,
use: loaders.null(),
},
],
},
});
externals: getConfig().externals.concat(function (
context,
request,
callback
) {
const regex = /^@?firebase(\/(.+))?/;
// exclude firebase products from being bundled, so
they will be loaded using require() at runtime.
if (regex.test(request)) {
return callback(null, "commonjs " + request); // <-
use commonjs!
}
callback();
});
}
};
现在的错误是:
WebpackError: TypeError: isRedirect 不是函数
我不知道该怎么办......
这里是repo,如果有帮助的话。
提前感谢您的宝贵时间。
【问题讨论】:
标签: webpack build gatsby reach-router