Loading

Vue-Router 路由属性解析

Vue-Router 路由属性解析

Vue2.0------Vue-Router 3.0


export default new Router({
    mode: 'history', //路由模式,取值为history与hash
    base: '/', //打包路径,默认为/,可以修改
    routes: [
    {
        path: string, //路径
        component: Component; //页面组件
        name: string; // 命名路由-路由名称
        components: ( ComponentName | ()=>import('页面地址') ); // 命名视图组件
        redirect: string | Location | Function; // 重定向
        props: boolean | string | Function; // 路由组件传递参数
        alias: string | Array<string>; // 路由别名
        children: Array<RouteConfig>; // 嵌套子路由
        beforeEnter?: (to: Route, from: Route, next: Function) => void; // 路由单独钩子
        meta: any; // 自定义标签属性,比如:是否需要登录
        icon: any; // 图标
        // 2.6.0+
        caseSensitive: boolean; // 匹配规则是否大小写敏感?(默认值:false)
        pathToRegexpOptions: Object; // 编译正则的选项
    }
]})

Vue3.0------Vue-Router 4.0

RouteRecordRaw=[
    path:string,//记录的路径。应该以 / 开头,除非该记录是另一条记录的子记录。可以定义参数:/users/:id 匹配 /users/1 以及 /users/posva。
    redirect:RouteLocationRaw | (to: RouteLocationNormalized) => RouteLocationRaw (可选), //重定向
	children:RouteRecordRaw 数组 (可选),//当前记录的嵌套路由。
    alias:string | string[] (可选)//路由的别名。允许定义类似记录副本的额外路由。这使得路由可以简写为像这种 /users/:id 和 /u/:id。 所有的 alias 和 path 值必须共享相同的参数。
    name:string | symbol (可选)//路由记录独一无二的名称。
    beforeEnter:NavigationGuard | NavigationGuard[] (可选)//在进入特定于此记录的守卫之前。注意如果记录有重定向属性,则 beforeEnter 无效。
    props:boolean | Record<string, any> | (to: RouteLocationNormalized) => Record<string, any> (可选)//允许将参数作为 props 传递给由 router-view 渲染的组件。当传递给一个多视图记录时,它应该是一个与组件具有相同键的对象,或者是一个应用于每个组件的布尔值。
    meta:RouteMeta (可选)//在记录上附加自定义数据。
]  
posted @ 2021-05-18 22:36  Howe_______ღ  阅读(572)  评论(0编辑  收藏  举报