如何在 next.js 中设置初始路由?

Hin*_*shi 1 reactjs next.js

如果我在react中设置初始路由,就有主页

package.json

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "homepage": "http://localhost:3001/admin",
...

Run Code Online (Sandbox Code Playgroud)

next.js 怎么样?
有解决办法吗?

mat*_*ki2 6

在 nextjs 中,您可以使用重写 - https://nextjs.org/docs/api-reference/next.config.js/rewrites

你的重写看起来像这样。

module.exports = {
  async redirects() {
    return [
      {
        source: '/',
        destination: '/admin',
        permanent: true,
      },
    ]
  },
}
Run Code Online (Sandbox Code Playgroud)