Vue——vue3路由重定向redirect写法
Vue——vue3路由重定向redirect写法
·
router\index.js 路由配置文件
import { createRouter, createWebHashHistory } from 'vue-router'
import Shop from '../components/shop.vue'
// 定义一些路由
const routes = [
{
path: '/mall',
// 写法一
// redirect: "/shop"
// 写法二
redirect: (to => { return { path: '/shop' } })
}
]
// 创建路由实例并传递 `routes` 配置
const router = createRouter({
// 内部提供了 history 模式的实现。为了简单起见,我们在这里使用 hash 模式。
history: createWebHashHistory(),
routes, // `routes: routes` 的缩写
})
export default router
使用:
在浏览器中输入
http://localhost:3000/#/mall或
直接跳转 shop页面
更多推荐
所有评论(0)