vue路由

路由

 

router-linkto='/home'  tag='button'  replace
router-view渲染路由页面
$route                谁处于活跃状态就是谁
$router整个大的路由对象

配置路由,在router/router.js下配置

import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'index',
      redirect: 'home',
      component: () => import('@/views/index/Index'),
      children: [
        {
          path: 'home',
          name: 'home',
          component: () => import("@/views/home/Home")
        },
        {
          path: 'news',
          name: 'news',
          component: () => import("@/views/news/News")
        },
        {
          path: 'comment',
          name: 'comment',
          component: () => import("@/views/comment/Comment")
        },
        {
          path: 'introduce',
          name: 'introduce',
          component: () => import("@/views/introduce/Introduce")
        },
        {
          path: 'contact',
          name: 'contact',
          component: () => import("@/views/contact/Contact")
        },

      ]
    },
    {
      path: "/admin",
      name: 'admin',
      component: () => import("@/views/admin/Admin"),
      redirect: '/admin/login',
      children: [
        {
          path: "login",
          name: 'login',
          component: () => import("@/views/login/Login")
        },
        {
          path: 'platformIndex',
          name: 'platformIndex',
          component: () => import("@/views/admin/platform/PlatformIndex"),
          children: [
            {
              path: 'commentManage',
              name: 'commentManage',
              component: () => import("@/views/admin/platform/CommentManage")
            },
            {
              path: 'chatRoom',
              name: 'chatRoom',
              component:  () => import("@/views/admin/platform/ChatRoom")
            },
            {
              path: 'imgManage',
              name: 'imgManage',
              component: () => import("@/views/admin/platform/imgManage"),
              redirect:'carouselImg',
              children: [
                {
                  path: 'carouselImg',
                  name: 'carouselImg',
                  component: () => import("@/views/admin/platform/CarouselImg"),
                }
              ]
            }
          ]
        }
      ]
    }
  ]
})

点击按钮到达指定路由

 searchInfo() {

      this.$router.push("/institutionalPlatform");

    },

replace跟push的区别是 前者没有返回的地址,后者有返回的地址

子路由

子路由跳转 url变化但是页面没变化 !!!!!!!!!!!!!!!!!
一定是父路由没有加 <router-view/>

{
      path: '/team',
      name: 'team',
      component: Team,
      children: [{
          path: '',
          name: 'teamManage',
          component: TeamManage
        },
        {
          path: 'searchLecturerInfo',
          name: 'searchLecturerInfo',
          component: SearchLecturerInfo
        },
      ]
    }, 

跳转到子模块  

searchLecturerInfo() {

      this.$router.push("/team/searchLecturerInfo");

    },

路由传递参数

第一种

取别人给User传递的参数

别人调用这个路由

第二种

到Profile并且传参数

取别人给Profile传递的参数

=================方法中路由跳转  刚才两个对应如下===================

 三级路由设置

{
    path: '/setClass',
    name: 'SetClass',
    component: SetClass,
    redirect: 'setClass/home',
    children: [
      // 首页
      {
        path: 'home',
        name: 'Home',
        component: Home,
        redirect: 'home/homeContent',
        meta: {
          title: 'home'
        },
        children: [
          {
            path: 'homeContent',
            name: 'HomeContent',
            component: HomeContent,
            meta: {
              title: 'home'
            }
          },
          {
            path: 'orderDetail',
            name: 'OrderDetail',
            component: OrderDetail,
            meta: {
              title: 'home'
            }
          },
          {
            path: 'watchDataAnalysis',
            name: 'WatchDataAnalysis',
            component: WatchDataAnalysis,
            meta: {
              title: 'home'
            }
          }
        ]
      },

push:添加一个路径(orderDetail),原来是setClass/home/homeContent 

则变成 setClass/home/orderDetail

路由开启新页面

 let routeUrl = this.$router.resolve({

            path: '/setClass/instructorPlatform/home'

          })

          window.open(routeUrl.href, '_blank')

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

江河地笑

实践是检验真理的唯一标准

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值