• vue-router createWebHashHistory


    https://next.router.vuejs.org/zh/installation.html

    创建项目是选上vue-router,没有选择vue-router的话要手动安装  

    npm install vue-router@4

    package.json

    App.vue

    <template>
      <div id="nav">
        <!-- 导航 -->
        <router-link to="/">Home</router-link> |
        <router-link to="/about">About</router-link> |
        <router-link to="/test1_bak">Test1_bak</router-link> |
        <router-link to="/test1">Test1</router-link> |
        <router-link to="/test2">Test2</router-link>
      </div>
      <!-- 路由出口 -->
      <router-view/>
    </template>
    
    <style>
    #app {
      font-family: Avenir, Helvetica, Arial, sans-serif;
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
      text-align: center;
      color: #2c3e50;
    }
    
    #nav {
      padding: 10px;
      background-color: lightskyblue;
    }
    
    #nav a {
      font-weight: bold;
      color: #2c3e50;
    }
    
    #nav a.router-link-exact-active {
      color:orangered;
    }
    </style>

    index.js

    //引入
    import { createRouter, createWebHashHistory } from 'vue-router'
    import Home from '../views/Home.vue'
    
    //创建路由对象
    const routes = [
      {
        path: '/',
        name: 'Home',
        component: Home
      },
        //路由重定向
      {
        path: '/home',
        redirect:'/'
      },
      {
        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')
      },
      {
        path: '/test1_bak',
        name: 'Test1_bak',
        // 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/Test1_bak.vue')
      },
      {
        path: '/test1',
        name: 'Test1',
        // 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/Test1.vue')
      },
      {
        path: '/test2',
        name: 'Test2',
        // 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/Test2.vue')
      }
    ]
    
    const router = createRouter({
      history: createWebHashHistory(),
      routes
    })
    
    //导出路由对象
    export default router

    main.js

    import { createApp } from 'vue'
    import App from './App.vue'
    //引入路由对象
    // import router from './router'
    import router from './router/index.js'
    
    createApp(App).use(router).mount('#app')

  • 相关阅读:
    【转】cocos2d-x使用第三方的TTF字体库
    CCControlSlider和CCControlStepper用法
    Cocos2d-x中获取设备语言的方法
    ccrendertexture
    【转】如何使用KeyChain保存和获取UDID
    【luogu P4777】【模板】扩展中国剩余定理(EXCRT)(数论)
    【luogu P1495】【模板】中国剩余定理(CRT)/曹冲养猪(数论)
    【luogu P3980】Volunteer / 志愿者招募(网络流)
    凡喵识图 / Image Recognition(鸽笼原理)(模拟)
    回文树(并查集)(倍增)(LCA)(ST 表)
  • 原文地址:https://www.cnblogs.com/mingforyou/p/15209936.html
Copyright © 2020-2023  润新知