vue-router(vue3)

1.页面跳转

impor { useRouter } from 'vue-router'
const router = useRouter()
router.push() // 相当于 vue中this.$router.push

2.router.js中

const routes = [
    {
        path: '/',
        component: Home,
        children: [
            {
                path: 'recommend', // 其中'/recommend'和'recommend'效果一样
                component: Recommend,
                alias: '/' // 别名 相当于访问'/recommend'但浏览器地址栏上是'/'
            },
            {
                path: 'book',
                component: Book,
                redirect: 'recommend' // 重定向
            }
        ]
    }
]

 

posted @ 2021-12-30 00:47  梦想行动家  阅读(192)  评论(0)    收藏  举报