vue-router 路由跳转的四种方法

vue-router 路由跳转方法

  1. router-link
      <router-link to="/">首页</router-link> |
      <router-link to="/blog">博客</router-link> |
      <router-link to="/video">视频</router-link> ||

  1. this.$router.push()
     <button @click="router_p">点击跳转router-push</button>

      methods:{
           router_p(){
            this.$router.push('/login')
          }
      }

  1. this.$router.replace() 同上push
  2. this.$router.go(n)
    向前或者向后跳转n个页面,n可为正整数或负整数

ps : 区别

  • this.$router.push

跳转到指定url路径,并想history栈中添加一个记录,点击后退会返回到上一个页面

  • this.$router.replace

跳转到指定url路径,但是history栈中不会有记录,点击返回会跳转到上上个页面 (就是直接替换了当前页面)

  • this.$router.go(n)

向前或者向后跳转n个页面,n可为正整数或负整数

posted @ 2021-10-16 19:02  老oo  阅读(2532)  评论(0编辑  收藏  举报