【发布时间】:2020-07-03 06:05:22
【问题描述】:
我的代码中有一部分,用于检查某事是否属实,然后重定向。
这是在这里完成的:
static async getInitialProps({ res }) {
let accessToken = settings.get('access_token');
if (accessToken) {
if (res) {
res.writeHead(301, {
Location: '/dashboard'
});
res.end();
return {};
}
}
}
它第一次重定向,但总是用上面的代码调用这个页面。
如果我重新启动我的应用程序,它会立即将我带到/dashboard 而不调用此第一页。它完全跳过它。什么可能导致这种行为?
我注意到我可以通过删除%appdata%/my-app 中应用的 AppData 来修复它。
我也在用:
const Store = require('electron-store');
const settings = new Store();
这是我的终端日志:
> electron-twitch-app@1.0.0 start C:\NodeApps\electron-twitch-app
> electron .
Defining routes from exportPathMap
(node:12868) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
event - compiled successfully
event - build page: /
wait - compiling...
event - compiled successfully
event - build page: /dashboard
wait - compiling...
event - compiled successfully
PS C:\NodeApps\electron-twitch-app> npm start
> electron-twitch-app@1.0.0 start C:\NodeApps\electron-twitch-app
> electron .
Defining routes from exportPathMap
(node:7500) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
event - compiled successfully
event - build page: /dashboard
wait - compiling...
event - compiled successfully
请注意,正如我所说 - 第一次,它调用/,然后重定向到/dashboard。第二次直接发到/dashboard。
【问题讨论】: