Vue 라우팅의 기본 구성 및 스크롤 동작

  1. 라우팅 기본 구성

export const constantRoutes = [
  {
    path: '/',
    redirect: '/home',     // 重定向
    component: Layout,     // 头部组件和尾部组件在这儿
    children: [
      {
        path: 'home',        // 路径
        component: () => import('@/views/home/Index'),  // 文件所在位置
        meta: { title: '首页' }
      },
      {
        path: 'product/hardware',
        component: () => import('@/views/product/Hardware.vue'),
        meta: { title: '产品-智能硬件' }
      },
   }
]
  1. 맨 위로 스크롤 동작으로 돌아가기

router/index.js 파일에도 구성되어 있습니다.

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    // 返回顶部
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

Guess you like

Origin blog.csdn.net/m0_65849649/article/details/128847469