<router-link :to="{path: `/orderConfirmation/${shopId}`}">
去结算
</router-link>
import { createRouter, createWebHashHistory } from 'vue-router'
const routes = [
{
path: '/',
name: 'Home',
component: () => import(/* webpackChunkName: "home" */ '../views/home/Home')
},
{
path: '/shop/:id',
name: 'Shop',
component: () => import(/* webpackChunkName: "shop" */ '../views/shop/Shop')
},
{
path: '/login',
name: 'Login',
component: () => import(/* webpackChunkName: "shop" */ '../views/login/Login'),
beforeEnter(to, from, next){
const { isLogin } = localStorage;
isLogin ? next({ name: 'Home'}) : next();
}
},
{
path:'/register',
name:'Register',
component: () => import(/* webpackChunkName: "shop" */ '../views/register/Register'),
beforeEnter(to, from, next){
const { isLogin } = localStorage;
isLogin ? next({ name: 'Home'}) : next();
}
},
{
path: '/cartList',
name: 'CartList',
component: () => import(/* webpackChunkName: "cartList" */ '../views/cartList/CartList')
},
{
path: '/orderConfirmation/:id',
name: 'OrderConfirmation',
component: () => import(/* webpackChunkName: "orderConfirmation" */ '../views/orderConfirmation/OrderConfirmation')
}
// {
// path: '/about',
// name: 'About',
// // route level code-splitting
// // this generates a separate chunk (about.[hash].js) for this route
// // which is lazy-loaded when the route is visited.
// component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
// }
]
const router = createRouter({
history: createWebHashHistory(),
routes
})
router.beforeEach((to,from,next)=>{
const isLogin=localStorage.isLogin;
if(!isLogin && ( to.name!=="Login" && to.name!=='Register')){
next({name:'Login'})
}else{
next();
}
})
export default router
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星