import {
createRouter, createWebHistory, RouteRecordRaw} from 'vue-router'
import Home from '../views/Home.vue'
import about from '../views/component/index.vue'
import Login from '../views/Login.vue'
import {
url} from '../common/utils'
import loginIndex from '../views/login/index.vue'
import aboutChildIndex from '../views/about/child/index.vue'
import one from '../views/component/one.vue'
import two from '../views/component/two.vue'
const routes: Array<RouteRecordRaw> = [
{
path: '/',
name: 'Home',
component: Home,
children: [
{
path: '/',
component: loginIndex,
children: [
{
path: '/',
component: aboutChildIndex
}
]
}
]
},
{
path: '/about',
name: 'about',
component: about,
children: [
{
path: '/about',
component: one,
children: [
{
path: '/about',
component: two
}
]
}
]
},
{
path: '/Login',
name: 'Login',
component: Login,
},
{
path: '/formIndex',
component: url('form/index')
}
]
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes,
linkActiveClass: 'active-class',
linkExactActiveClass: 'init-class',
scrollBehavior (to, from, savedPosition):any {
console.log(to, from , savedPosition)
if(savedPosition) {
return savedPosition;
}else{
return {
x:0,y:0}
}
}
})
router.beforeEach((to,from,next)=>{
console.log(to,from)
next()
})
router.afterEach((to,from)=>{
console.log(to,from)
})
router.addRoute({
path: '/one',
component: one
})
export default router