当我的代码部署到Heroku时,我遇到了一个奇怪的问题。在本地主机上,我可以来回访问所有路由。部署到Heroku后,一旦用户通过身份验证(即/ homes / main),主登陆页面仍然可以呈现。但是一旦离开它,我就无法回到/ homes / main(例如,进入/ homes / new或/ homes / pay之后)。导航返回的唯一方法是更改浏览器网址。我将Express&Passport用于单点登录,将next-router用于路由反应前端。
更糟糕的是,通过事件处理到/ homes / main的程序化路由也不起作用。请帮忙!
routes.js
const routes = require('next-routes')();
routes
.add('/homes/main', '/homes/main')
.add('/homes/new', '/homes/new')
.add('/homes/pay', '/homes/pay');
module.exports = routes;
server.js
const express = require("express");
const keys = require("./config/keys");
const mongoose = require("mongoose");
const cookieSession = require('cookie-session');
const bodyParser = require('body-parser');
const passport = require('passport');
require('./models/Users');
require("./services/passport");
mongoose.connect(keys.mongoDBURI);
const app = express();
app.use(bodyParser.json());
app.use(cookieSession({
maxAge: 30*24*60*60*1000,
keys: [keys.cookieKey]
}
));
app.use(passport.initialize());
app.use(passport.session());
require("./routes/authRoute")(app);
const next = require('next');
const routes = require('./routes');
const next_app = next({
dev: process.env.NODE_ENV !=='production'
});
const handler = routes.getRequestHandler(next_app);
next_app.prepare().then(()=>{
const PORT = process.env.PORT || 5000;
app.use(handler).listen(PORT, (err)=>{
if(err) throw err;
console.log(`Ready on port: ${PORT}`);
});
});
package.json
....
"scripts": {
"start": "NODE_ENV=production node server.js",
"dev": "node server.js",
"build": "next build",
"heroku-postbuild": "next build"
}
....
我的目录:
/页
/ pages / homes
/pages/homes/main.js
/pages/homes/new.js
/pages/homes/pay.js