在index.js

import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from "../components/HelloWorld";
import Hi1 from "../components/Hi1";
import Hi2 from "../components/Hi2";
import params from "../components/params";

Vue.use(Router)//vue全局使用Router

export default new Router({
  routes: [//参数为数组
    {
    path:"/goHome",
      redirect:'/' //重定向到首页
    }


  ]
})

app.vue中

<template>
  <div id="app">
    <img src="./assets/logo.png">
    <router-link to="/">首页</router-link> |
    <router-link to="/goHome">回首页</router-link> |//重定向回到首页
    <router-view/>
  </div>
</template>

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

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

可以带参数,带参数方法参考

Logo

前往低代码交流专区

更多推荐