Vue Router对象创建
Vue Router构建选项详解参数 类型 默认值 可选值 描述 routes Array 配置路由规则 mode string “hash” (浏览器环境) /“abstract” (Node.js 环境) “hash”/“history” / “abstract” 配置路由模式 base string / 应用的基路径 linkActiveClass string router-link-exact-active 全局配置 默认的精确激活的 class scrollBehavior Function 配置滚动行为 parseQuery / stringifyQuery Function 提供自定义查询字符串的解析/反解析函数 fallback boolean 当浏览器不支持 history.pushState 控制路由是否应该回退到 hash 模式。默认值为 true
Vue RouteConfig 的类型定义export interface RouteConfig {
path: string;
name?: string;
component?: Component;
components?: Dictionary<Component>;
redirect?: RedirectOption;
alias?: string | string[];
children?: RouteConfig[];
meta?: any;
beforeEnter?: NavigationGuard;
props?: boolean | Object | RoutePropsFunction;
caseSensitive?: boolean;
pathToRegexpOptions?: PathToRegexpOptions;
}
属性 详解 path 路径 name 命名路由 component 命名视图组件 components 命名视图组件 redirect 重定向路径 alias 别名 children 嵌套路由 meta 路由元信息 使用$route.meta.属性可以获取 caseSensitive 匹配规则是否大小写敏感?(默认值:false) pathToRegexpOptions 编译正则的选项
Vue Router Mode详解hash: 使用 URL hash 值来作路由。支持所有浏览器,包括不支持 HTML5 History Api 的浏览器。
history: 依赖 HTML5 History API 和服务器配置。查看 HTML5 History 模式。
abstract : 支持所有 JavaScript 运行环境,如 Node. js 服务器端。如果发现没有浏览器的 API,路由会自动强制进入这个模式。