使用nextjs 构建 预生成SPA应用,使用route.push时页面刷新的问题

nextjs 使用导出方式部署的时候,可以在任意服务器部署,而无需进行任何配置。与其他框架相比,next的核心优势就是可以进行SSR,可以有更快的首屏加载,防止首页白屏。

使用以下配置可以以静态方式部署,服务器也无需进行任何配置

{
    output:"export",
    trailingSlash: true
}

 

路由间跳转可以使用

import { useRouter } from "next/navigation";

const router=useRouter();
router.push可以跳转到新的页面,但需要注意的是因为使用了trailingSlash: true,所以在跳转时页面必须要/结尾,例如
router.push("/about/")

 

posted @ 2024-03-07 13:11  CY_Lee  阅读(528)  评论(0)    收藏  举报