首页 > 解决方案 > 在使用 nuxt-link 转到新页面之前存储 url

问题描述

我想在浏览器的主页上存储我的 url,/main然后再使用nuxt-link. 这是我的nuxt-link

<NuxtLink
  :to="`/search?param={number}`"
  @click.native="assignAddress"
>
  SEARCH
</NuxtLink>

这是通过单击触发的方法nuxt-link

assignAddress() {
  localStorage.setItem("address", `${this.$route.path}`);
},

问题是它保存/search在浏览器中。我认为发生的是assignAddress在 nuxt 更改页面后触发了该方法!

如何先将 url 存储在浏览器中,然后更改页面,以便在我的浏览器中存储/main而不是/search

标签: javascriptvue.jsurlnuxt.jsnuxt-link

解决方案


@seyet 您如何尝试在beforeRouteLeave导航守卫中设置它。

beforeRouteLeave(to, from, next) {
  // called when the route that renders this component is about to
  // be navigated away from.
  // has access to `this` component instance.
}

链接到此处找到的文档

完成后请务必致电next()


推荐阅读