GetServersideProps断开NextJ/电容器中的路由
我使用以下方法来避免使用NextJS构建时导出GetServersideProps:
export const getServerSideProps = process.env.SKIP_SSR ? undefined : async (ctx) => { ... }
我的构建:
"build:ios": "SKIP_SSR=1 next build && SKIP_SSR=1 next export && npx cap copy ios",
这确实很好,除了在导出并作为iOS应用程序导航运行时不起作用。
为了使其尽可能简单,我已经在页面/index.tsx中添加了此
if(!route.asPath.startsWith('/p/home'))
route.push('/p/home')
return (
<div className={styles.container}>
I am here in the root page {window.location.href}
</div>
)
内容:“我在根页面电容器中:// localhost/p/home”
我想看到的页面实际上是在/p/home/index.tsx中,但是渲染的是页面/索引。
我发现原因是GetServersideProps,即使我以某种方式跳过了SSR,它正在通过电容器中的构建和破坏路由。
如果我评论getServersideprops,它运行良好。
是否有一种方法可以在进行构建时正确删除GetServersideProps?
I use the following method to avoid exporting getServerSideProps when building with nextjs:
export const getServerSideProps = process.env.SKIP_SSR ? undefined : async (ctx) => { ... }
And I build with:
"build:ios": "SKIP_SSR=1 next build && SKIP_SSR=1 next export && npx cap copy ios",
This works really well except that when exported and run as an iOS app navigations do not work.
To make it as simple as possible, I have added this in pages/index.tsx:
if(!route.asPath.startsWith('/p/home'))
route.push('/p/home')
return (
<div className={styles.container}>
I am here in the root page {window.location.href}
</div>
)
Which is outputting: "I am here in the root page capacitor://localhost/p/home"
The page I want to see rendered is actually in /p/home/index.tsx but what renders is pages/index.
I found out the cause of this is getServerSideProps, even though I skip ssr somehow it's getting through on the build and breaking routing in Capacitor.
If I comment out getServerSideProps it runs fine.
Is there a way to properly remove getServerSideProps when doing a build?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,并使用webpack插件 preprocessor-loader-loader 。
webpack-preprocessor-loader
to devDepencies#!if
and #!endif 围绕getserverversidepropsI was encountering the same problem and solved it using a webpack plugin preprocessor-loader.
webpack-preprocessor-loader
to devDepencies#!if
and#!endif
comment around getServerSideProps