SoFunction
Updated on 2025-04-06

Simple use of vue router 2.0 secondary routing

This article shares the specific code of vue router 2.0 secondary routing for your reference. The specific content is as follows

1.

<template>
 <div >
  <router-view></router-view>
 </div>
</template>

2. In router (path configuration for routing)

import Vue from 'vue'
import Router from 'vue-router'
import Hello from '@/components/Hello'
import Login from '@/components/Login'
import index from '@/components/index'
import Header from '@/components/Header/Header'
import Product from '@/components/Product/Product'

(Router)

export default new Router({
 routes: [
  {
   path: '/',
   name: 'Login',
   component: Login
  },
  {
   path: '/index',
   name: 'index',
   component: index,
   children: [ //This is the configuration of the secondary routing    {
     path: '/hello',
     name: 'Hello',
     component: Hello
    },
    {
     path: '/header',
     name: 'Header',
     component: Header
    },
    {
     path: '/product',
     name: 'Product',
     component: Product
    }
   ]
  }
 ]
})

3. Here is the code in our

<template>
 <div class="aaa">
  <div class="list-group">
    <router-link to="/hello">Go to hello</router-link>
    <router-link to="/header">Go to header</router-link>
    <router-link to="/product">Go to product</router-link>
    <input type="text" v-model="username">
    <button v-click="text"></button>
    <router-view></router-view>
  </div>
 </div>
</template>

4. Finally, we create new components such as hello, header, and product to verify our effect. I won’t make a demonstration here because I have tested it myself, so there is no problem.

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.