vue中路由的用法:
const routes = [ { path: "/", redirect: '/welcome' }, { path: "/welcome", component: home, children:[ { path: "/welcome" ,component: welcome }, { path: "/form" ,component: form }, ]}, { path: "/login" ,component: login } ] //path: 訪問的路徑 //redirect: 重定向的路徑 //component: 加載的組件 //children:[] 二級路由 //name: 路由的名字
vue中路由實現點擊跳轉:
<div @click="gotoMenu">按鈕</div>
methods: { gotoMenu(){ //指定跳轉的地址 this.$router.replace('/menu') //通過push進行跳轉 this.$router.push('/menu') //指定跳轉的路由的名字下 this.$router.replace({name:'menu'}) //跳轉到上一次瀏覽的頁面 this.$router.go(-1) } }, }