【发布时间】:2020-02-06 17:13:33
【问题描述】:
我是 next.js 的新手。 我正在后端渲染我的页面视图:
module.exports = (server, app) => {
server.get('/setup', (req, res) => {
const testData = {
name: "Test",
testProp: "testVal",
};
return app.render(req, res, '/setup', testData);
});
};
当我在浏览器中刷新 /setup 路由上的页面时,我可以看到 getInitialProps 中的数据,这很好。但是当我从另一条路线导航到/setup 路线时,我看不到数据。为什么会发生这种情况,如何更改它以查看数据?这是我的页面代码:
import { withAuth } from '../utils/withAuth';
const Setup = props => {
console.log(props); // when linking there is no expected data here
return(
<div>Setup here</div>
)
};
Setup.getInitialProps = async ctx => {
return { ...ctx.query };
};
export default withAuth(Setup);
【问题讨论】:
-
只有当路由是 '/setup' 时你才传递数据。
-
但我正在从另一条路线导航到 /setup 路线
标签: reactjs next.js server-side-rendering