gpt4 book ai didi

vue.js - 页面刷新时丢失 router.params

转载 作者:行者123 更新时间:2023-12-03 06:48:56 24 4
gpt4 key购买 nike

我遇到了 vue-router 的问题。
我在主页上得到了一个帖子列表。当我单击其中之一时,它会重定向到帖子页面,例如:
<router-link :to="{ name: 'article', params: {id: article.id, slug: article.slug } }"></router-link>

一切正常,我可以使用 this.$route.params.id 检索正确文章的数据在 setter/getter 中。

我的问题:当我重新加载文章页面时,this.$route.params.id未定义,这会导致整个应用程序崩溃。

如何保存 router.params尽管页面重新加载?

最佳答案

你用的是什么后端?您需要enable history mode on your router ,以及在您的后端 Web 服务器上进行一些额外的配置更改。 Please refer to this link for the additional server side configuration changes您需要使其正常工作。
另外,please make note of this 404 caveat使用时 history mode ..
编辑:你可以试试 something like this因为 ID 在 URL 中保持不变:从 MIKE AXLE 寻找解决方案

I don't know if anyone else if facing the same issue, but I was having a problem getting route params on refresh. The route parameter I was trying to get was an ID number and I use that ID to fetch data and populate the page. I found (through many console logs) when I refreshed, the number was turning into a string and thats why the page was not working. I sorted it out but casting the ID to number before using it:

Number($route.params.id)

关于vue.js - 页面刷新时丢失 router.params,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55813765/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com