vueルーティングとルーティングガード
10925 ワード
ルーティングの追加
ルーティングジャンプ
ルーティングリダイレクト
redirectによるルーティングのリダイレクト
サブルートの定義
ルーティングパラメータ を実現する.は、 を取得することができる.
ルーティング構成はname値によってルーティングを決定し、paramsによって を伝達する.はpathマッチングルーティングによりqueryにより伝達する である.
ルーティングガード
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Detail from '../views/Detail.vue'
Vue.use(VueRouter)
const routes = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/detail',
name: 'Detail',
component: Detail
},
{
path: '/about',
name: 'About',
component: () => import('../views/About.vue')
}
]
const router = new VueRouter({
routes
})
export default router
ルーティングジャンプ
によるルーティングジャンプ
で表示ルーティングリダイレクト
redirectによるルーティングのリダイレクト
{
path: '/',
name: 'Home',
component: Home,
redirect:'/detail'
},
{
path: '/detail',
name: 'Detail',
component: Detail,
},
サブルートの定義
{
path: '/detail',
name: 'Detail',
component: Detail,
children:[
{
path: 'info',
// "/" , "/";
name: 'Info',
component: Info,
},
]
},
ルーティングパラメータ
$router.push
を用いる携帯パラメータジャンプthis.$route.params.id
を使用してパラメータgetDetail(id) {
this.$router.push({
path: `/detail/${id}`,
})
ルーティング構成
{
path: '/detail/:id',
name: 'Detail',
component: Detail
}
this.$router.push({
name: 'Detail',
params: {id: id}
})
this.$router.push({
path: '/Detail',
query: {
id: id
}
})
ルーティングガード
router.beforeEach((to, from, next) => {
//to , from , next , , next()
console.log(to);
if (to.path !== '/login') {
if (window.isLogin) {
next()
} else {
next('/login?redirect='+ to.path)
}
} else {
next()
}
})