周凯,个人博客

  • 前端
  • 嵌入式
  • 工具
  • 后端
  • 随笔
个人记录
  1. 首页
  2. 前端
  3. react
  4. 正文

nextjs export 静态页面时避免出现404

2023年 7月 7日 1013点热度 0人点赞 1条评论

问题

  • 当你写完多个页面,exoprt静态页面后,放在服务器上直接访问某个子页面**​**,发现直接访问给你返回了个404,你去查看目录结构,发现nextjs工具给你生成了register.html。而不是/register/index.html。自然会返回404

解决办法

  • 官方文档也有提及

    修改next.config.js 。添加 exportTrailingSlash: true

    module.exports = withLess({
    exportTrailingSlash: true, // make /about becomes /about/index.html and is routable via /about/.
    lessLoaderOptions: {
      modifyVars: {
        'primary-color': '#9324af',
        'secondary-color': '#333333'
      },
      javascriptEnabled: true
    },
    })
    • 修改后效果

🎯 拓展阅读提示

本文涉及的内容已同步至公众号后台,我会在那里分享更多深度内容和实用技巧

→ 点击关注:一行梦境

公众号二维码
本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: 暂无
最后更新:2023年 7月 7日

周凯

这个人很懒,什么都没留下

打赏 点赞
< 上一篇
下一篇 >

文章评论

  • Avatar
    上海网站建设

    感谢分享

    2023年 7月 12日
    回复
  • razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
    取消回复

    COPYRIGHT © 2022-现在 周凯,个人博客. ALL RIGHTS RESERVED.

    Theme Kratos Made By Seaton Jiang

    蒙ICP备18004897号