Answer the question
In order to leave comments, you need to log in
Why does the router show the wrong page when refreshing the page?
index.js
{
path: "/news/:title",
name: "NewsPost",
component: () => import("../views/NewsPost.vue")
}
<router-link
:to="{
name: 'NewsPost',
params: {
title: `${news.title.toLowerCase().replace(/\s+/g,'-')}`,
id : news.id
}
}"
>{{news.title}}</router-link>
Answer the question
In order to leave comments, you need to log in
It can be assumed that your content loading is not associated with the title
, which is in the url, but with id
, which is transmitted hidden and, of course, when the page is refreshed, it will not magically appear from anywhere. Refreshing the page is, in fact, just a new transition to the url that is in the address bar. If the address bar doesn't give your components enough information to know what to display, how will they display what you want?
You must store the connection somewhere title
and id
, or requests must go to the server via title
.
Of course, you can remember in cookies or some other storage a specific bundle title
andid
for a specific user, but this will make the links meaningless and impossible to transfer to others.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question