我在生产环境中我的React应用程序的路线有问题,它们仅与Chrome一起使用。在所有其他浏览器中,路由总是将路由重定向到登录页组件。我不明白为什么在开发环境中该路由为所有浏览器工作。
我有这样的路线:
<Switch>
<GuestRoute
location={location}
path="/signup"
exact
component={SignupPage}
/>
<GuestRoute
location={location}
path="/forgot_password"
exact
component={ForgotPasswordPage}
/>
<GuestRoute
location={location}
path="/reset_password/:token"
exact
component={ResetPasswordPage}
/>
<UserRoute
location={location}
path="/"
exact
component={DashboardPage}
/>
<GuestRoute location={location} component={LoginPage} />
</Switch>
这些组件中的三个使用Redux,因此我尝试使用包装器" fratorter"来解决该问题。但没有起作用。
知道为什么会发生这种情况?
解决我问题的解决方案是更改提供静态文件的方式。
之前:
app.use(express.static(`${__dirname}/build`));
app.get('*', function(req, res) {
res.redirect('/');
});
之后:
app.use(express.static(path.join(__dirname, 'build')));
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
感谢米歇尔(Michel(,他帮助我找到了错误。