【发布时间】:2019-03-26 02:13:13
【问题描述】:
我正在尝试使用 Next 为 Electron 应用程序供电。 electron-next 使用 Next 的静态站点模式进行生产构建,它在构建时调用 getInitialProps,而不是在启动时。
start.js(初始渲染页面)
import Link from 'next/link'
export default function Start({date}) {
return (
<div>
<div>Date is {date}</div> {/* <- will always be the build time */}
<Link href="/about">
<a>Take me to the About page</a>
</Link>
</div>
)
}
Start.getInitialProps = () => {
return {
date: "" + new Date()
}
}
有趣的是,使用Link 导航到别处实际上会导致动态的getInitialProps 调用。
about.js
import Link from 'next/link'
export default function About({date}) {
return (
<div>
<div>Date is {date}</div> {/* <- will be the time the link was clicked */}
<div>Important info about this app</div>
</div>
)
}
About.getInitialProps = () => {
return {
date: "" + new Date()
}
}
有没有一种简单的方法来获取初始路由的动态行为?我想这在静态网站中也会有很多用例。
【问题讨论】:
标签: next.js static-site