javascript Vue 3:Router.push更改URL但不加载页面

p5fdfcr1  于 2023-10-14  发布在  Java
关注(0)|答案(1)|浏览(188)

我正在尝试从/checklist/1/item/2导航到/checklist/2/item/1

this.$router.push({ name: 'checklistitem', params: { id: this.id, aid: this.aid } });
这会更改浏览器中的URL,但不会加载(呈现)带有新数据的页面。
路由器是用这些

import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  },
  {
    path: '/checklist/:id',
    name: 'checklist',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AcChecklistsView.vue'),
    props: true
  },
  {
    path: '/checklist/:id/item/:aid',
    name: 'checklistitem',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/ChecklistView.vue'),
    props: true
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  mode: 'history',
  routes
})

export default router

有人知道出了什么问题吗?
谢谢

h79rfbju

h79rfbju1#

通过传递带有“replace:true”在可选的“to”属性中,所以它会是。

this.$router.push({ name: 'checklistitem', params: { id: this.id, aid: this.aid }, replace: true });

相关问题