Pass props in url using Next.js

别等时光非礼了梦想. 提交于 2021-01-29 19:40:47

问题


I pass props in url using this:

const sendPropsInRoute = (data) => {
    router.push({
      pathname: '/cars/car',
      query: { data: JSON.stringify(data) },
    },
      `/agencies/agency`,
      {
        shallow: true,
      },
    )
  }

Everything works fine when i click on the button. I am redirected on the page and i read the data from query in this way:

const router = useRouter();
const car = router.query.data;
console.log(car)

Issue: When i refresh the page where i was redirected i loose the data from query.
Question: How to keep data from query even when i refresh the page?

来源:https://stackoverflow.com/questions/64662714/pass-props-in-url-using-next-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!