Vue.js--전역수위

1241 단어 Vue
전역 수위
const routes=[
	{path:'/',name:"homeLink",component:Home},
	{path:'/menu',component:Menu},	
	{path:'*',redirect:'/'}
]
const router=new VueRouter({
	routes,
	mode:"history"
})
router.beforeEach((to,from,next)=>{
	//   store.gettes.isLogin===false
	if(to.path=='/login' || to.path=='/register'){
		next();
	}else{
		alert("     ,    ");
		next('/login')
	}
	
})

구성 요소 수위
const routes=[
	{path:'/',name:"homeLink",component:Home},
	{path:'/admin',component:Admin,
		 beforeEach:(to,form,next)=>{
		 	if(store.gettes.isLogin===false){
		 		alert("     ,       !");
		 		next('/login')
		 	}else{
		 		next();
			}
		 }
    },
	{path:'*',redirect:'/'}
]

라우팅 시작 후
	export default{

		data(){
			return {
				name:"Henry"
			}
		},

		beforeRouteEnter: (to,from,next) =>{
			
			next(vm=>{
				alert("Hello " + vm.name)
			})

		},

		beforeRouteLeave: (to,from,next) =>{

			if(confirm("     ?")==true){
				next()
			}else{
				next(false)
			}

		}
	}
    //vm               

좋은 웹페이지 즐겨찾기