首页 > 解决方案 > NextJS:在 ExportPathMap 中设置动态路径

问题描述

我在不使用 getStaticPath 的情况下完成了 NEXT JS 项目,我正在尝试部署它。但是,我无法弄清楚如何在 ExportPathMap 中设置动态路径。我通过 获取参数数据useRouter(),它在本地 100% 正确工作,但在部署版本上失败。

这是我的 next.config.js 文件:

const withImages = require('next-images')
module.exports = withImages()

module.exports = withImages({
images: {
    loader: "imgix",
    path: "",
},
exportPathMap: async function (
    defaultPathMap,
    { dev, dir, outDir, distDir, buildId }
  ) {
    return {
      '/': { page: '/' },
    }
  },
})

我的动态路径是 localhost:3000/[pid] 和 localhost:3000/[pid]/[jobid]。

我不知道如何使用 getStaticPath,因为文档引用了一些预加载的 JSON 数据,但我正在尝试实现其他目标。

标签: javascriptreactjsnext.js

解决方案


推荐阅读