javascript - 在使用 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
?
解决方案
@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()
。
推荐阅读
- docker - Docker 与 Kubernetes
- haskell - 为什么安装 Haskell 包不起作用?
- angular - 在焦点和离开焦点时从材料输入中删除标签
- r - 根据R中的索引值重复比较数据集的同一部分与数据集的其他部分
- html - 如何在引导程序中获得所需的网格布局
- node.js - 使用 req.body 从 body 读取属性
- google-sheets - 无法在 Google 表格中使用 Importxml 获取网站数据
- javascript - 函数使用对象来启动和销毁资源。如何将其重写为提供资源的 HOF?
- javascript - 按分类列出自定义帖子类型中的所有帖子不起作用
- python - Python:如何创建每次包含 X 字节的数据块