/* @flow */
import type VueRouter from '../index'
// parsePath:用于拆分成 { path: string, query: object, hash: string } 的形式。
// resolvePath: 用于将相对路径根据 current route 拼接路径成绝对形式的路径。
import {
parsePath, resolvePath } from './path'
//resolveQuery() 将所有的 query 统一到一个对象中。
import {
resolveQuery } from './query'
//fillParams 将 routes 中配置的动态参数,用 params 传参进行填充。
import {
fillParams } from './params'
//警告
import {
warn } from './warn'
//用于数据的浅拷贝
import {
extend } from './misc'
/*
normalizeLocation() 归一化路径
第一个参数: to, 可以是对象,也可以是对象。
第二个参数: current,就是 this.$route 对象。
{
fullPath: "/" //完整路径。
hash: "" //hash部分的字符串。
matched: [] //record 数组。
meta: {} //record 中记录的 meta。
name: null //路由名字
params: {} //路径动态参数 比如: /:userId
path: "/" //短路径
query: {} //?后面的参数
}
第三个参数:append, 表示相对路径是否追加基准路径。
第四个参数:router, 就是 this.$router 对象。
localtion 返回的结果为:
return {
_normalized: true,
name, //name, path 同时存在的情况下,优先使用 name。
path, //就是 window.location.href 的 pathname 部分。
query,
hash,
}
*/
export function normalizeLocation(
raw: RawLocation,
current: ?Route,
append: ?boolean,
router: ?VueRouter
): Location {
//如果 raw 是字符串,则
vue-router3 源码注释系列 /src/util/location.js
最新推荐文章于 2024-04-26 16:47:03 发布