如果没有 nextjs 页面使用 IIS 页面
If no nextjs page use IIS page
如果在IIS上部署nextjs,如果没有nextjs页面,有没有办法默认回到IIS进行路由?
我想用nextjs做我的主页和wiki等,但是如果没有页面jsx,还有其他页面直接从IIS路由?
例)
- homepage.com -> 加载 nextjs page/index.js
- homepage.com/wiki/some-page -> 加载 nextjs page/wiki/[some-page].js
- 主页。com/viewer -> 加载 iis/viewer/index。html
两个选项
使用 nginx 等代理前端应用程序并维护静态路由,例如:/viewer
-> /iis/viewer/index.html
在 nextjs 中将您的 404 页面配置为重定向。首先设置一个 custom App with next,然后在你的应用 getInitialProps
中接收一个 ctx
// Modified from https://github.com/vercel/next.js/discussions/16749#discussioncomment-1604423
if (ctx.res.statusCode === 404) {
res.writeHead(301, { Location: '/iis/'+ctx.asPath })
res.end()
}
请注意,必须在 IIS 端设置当 IIS 收到 404 页面时的适当处理。
如果在IIS上部署nextjs,如果没有nextjs页面,有没有办法默认回到IIS进行路由?
我想用nextjs做我的主页和wiki等,但是如果没有页面jsx,还有其他页面直接从IIS路由?
例)
- homepage.com -> 加载 nextjs page/index.js
- homepage.com/wiki/some-page -> 加载 nextjs page/wiki/[some-page].js
- 主页。com/viewer -> 加载 iis/viewer/index。html
两个选项
使用 nginx 等代理前端应用程序并维护静态路由,例如:
/viewer
->/iis/viewer/index.html
在 nextjs 中将您的 404 页面配置为重定向。首先设置一个 custom App with next,然后在你的应用
getInitialProps
中接收一个ctx
// Modified from https://github.com/vercel/next.js/discussions/16749#discussioncomment-1604423
if (ctx.res.statusCode === 404) {
res.writeHead(301, { Location: '/iis/'+ctx.asPath })
res.end()
}
请注意,必须在 IIS 端设置当 IIS 收到 404 页面时的适当处理。