nuxtjs页面不会刷新,也无法访问

6g8kf2rb  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(379)

我的nuxtjs应用程序刷新页面时出现问题 (F5) .
假设我在这一页 https://example.com/foo/bar (等于 https://example.com/foo/bar/index.html )我按下刷新按钮,页面在一段时间后不会重新加载 this site can't be reached 错误。
但是当我用斜线划的时候 / 最后,它完全重新加载。
此外,我无法在结尾或结尾处没有斜杠直接访问页面 /index.html 当我这样做的时候,它会变成 https://example.com/foo/bar .
你知道怎么解决这个问题吗?
我不想用 router: { trailingSlash: false }, 因为我读到这篇文章会影响我的搜索引擎优化。
我还添加了以下内容:nuxtjs静态生成的html页面在调用/index.html时不会加载javascript,但它并没有解决这个问题,而是解决了我遇到的另一个问题。
我的 nuxt-config.js :

router: {
//https://stackoverflow.com/questions/63719727/nuxtjs-static-generated-html-page-does-not-load-javascript-when-calling-index-h
extendRoutes(routes) {
  routes.forEach((route) => {
    // When options.generate.subFolders is true (default)
    const alias = route.path.length > 1 ? `${route.path}/index.html` : '/index.html'

    // When options.generate.subFolders is false
    // const normalizedRoute = route.path.replace(/\/$/, '') // Remove trailing slashes if they exist
    // const alias =
    //   route.path.length > 1 ? `${normalizedRoute}.html` : '/index.html'

    route.alias = alias
  })
},

},

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题