Installation und Verwendung von Vue-Routing

index.js im Router-Ordner im SRC-Ordner ;

import Vue from 'vue'
import vueRouter from 'vue-router'
const Home= () => import('../pages/Home.vue')
Vue.use(vueRouter)

const routes = [
    {
        path:'',
        redirect:'/home'
    },
    {
        path:'/home',
        component:Home,
        meta:{
        }
    }];
    const router = new vueRouter({
        routes,
        mode:'history'
    }); 
    
    const originalPush = vueRouter.prototype.push
    vueRouter.prototype.push = function push(location) {
      return originalPush.call(this, location).catch(err => err)
    
    };
     
    export default router;

Fügen Sie den Router in die Datei main.js ein 

import Vue from 'vue'
import App from './App.vue'
import router from './router/app'   // 引入router

Vue.config.productionTip = false
new Vue({
  router,
  render: h => h(App),
}).$mount('#app')

Wie konfiguriere ich die App.vue-Datei? Schau runter

<template>
  <div id="app">
    <keep-alive exclude="searchResult">
      <router-view :key="$route.fullPath"></router-view>
    </keep-alive>
  </div>
</template>

<script>
export default {
  name: 'App',
  components: {
  }
}
</script>

<style>

</style>

Supongo que te gusta

Origin blog.csdn.net/m0_73358221/article/details/127978267
Recomendado
Clasificación