首页 > 其他分享 >路由的嵌套

路由的嵌套

时间:2022-11-19 16:25:48浏览次数:42  
标签:const .. component 嵌套 components path import 路由

home路径下配置一个news和message子路径

import Vue from 'vue'
import VueRouter from 'vue-router'
const Home = () => import('../components/Home')
const HomeNews = () => import('../components/HomeNews')
const HomeMessage = () => import('../components/HomeMessage')

const About = () => import('../components/About')
const User = () => import('../components/User')

//1.通过Vue.use(插件),安装插件
Vue.use(VueRouter)

//2.创建VueRouter对象
const routes = [
    {
     path:'/',
     //重定向到home
     redirect: '/home'
    },
    {
     path:'/home',
     component: Home,
     children: [
        {
            path: '',//设置嵌套路由默认路径
            redirect: 'message'
        },
        {
            path: 'news',//子组件不能加/
            component: HomeNews
        },
        {
            path: 'message',
            component: HomeMessage
        }
     ]
    },
    {
        path:'/about',
        component: About    
    },
    {
        path: '/user/:userName',
        component: User
    }
]

const router = new VueRouter({
    mode: 'history',//使用history模式,去除url中的#符号(hash模式)
    //配置路由和组件之间的应用关系
    routes
})

//3.将router对象传入到vue实例
export default router

  

创建HomeNews和HomeMessage组件

 

 

 

 

Home组件中使用<router-link>和<router-view>

 

标签:const,..,component,嵌套,components,path,import,路由
From: https://www.cnblogs.com/ixtao/p/16906306.html

相关文章

  • 硬路由刷OpenWrt的网络拓扑
    硬路由看似有很多网口,但其实只有一张网卡(一个网口),所有的网口都是通过划分VLAN来实现不同的功能。如下图:硬路由有5个网口。其中Port0属于VLAN1,作为WAN口。Port1~Port4属......
  • 83:嵌套函数_内部函数_数据隐藏
    ###嵌套函数(内部函数)嵌套函数:在函数内部定义的函数!deff1():print('f1running...')deff2():print('f2running...')f2()f1()输出结果:......
  • 动态路由的使用
    :to绑定参数  /:参数名,进行拼接参数  $route.params.参数名,取参数值    ......
  • 华三和华为的交换机/路由器命名规则
    华三和华为的交换机/路由器命名规则华三交换机:H3CS5500-28C-EIH3C 是华三的品牌名称S指交换机,SR指路由器S5500 指子产品系列产品系列:9 核心机箱式交换机7 高端......
  • 解决SPA单页面应用(create-react-app,Vue-cli)路由跳转后404的问题。
    在Nginx中配置try_filesserver{listen80;server_namelocalhost;root"****";location/{ try_files$uri$uri/......
  • 路由原理hash和history
    hash和history都是运用于前后端项目分离的要清楚两者的区别以及两者各自的使用场景,还有各自的使用特点和优缺点hash是由#后面拼接的真实url路径history是h5新增的特性......
  • 通过代码跳转路由
    <template><divid="app"><button@click="toHome">首页</button><buttonto="/about"@click="toAbout">关于</button><!--相当于占位符--><r......
  • 59:嵌套循环练习_九九乘法表_打印表格数据
    【操作】利用嵌套循环打印九九乘法表forminrange(1,10):forninrange(1,m+1):print("{0}*{1}={2}".format(m,n,(m*n)),end="\t")print()输......
  • 58:嵌套循环
    ###嵌套循环和综合练习一个循环体内可以嵌入另一个循环,一般称为“嵌套循环”,或者“多重循环”。【操作】打印如下图案forxinrange(5):foryinrange(5):......
  • 复杂路由
    一、嵌套路由:可在单页应用框架下开发多页应用。思想:嵌套路由其实是router-view的细化,router-view第一层中包含一个router-view,路由children路由。每一个坑挖好都要对......