History库源码分析-createPath

2023-11-15 11:40:40

createPath(to: To): string

To interface

interface To = Partial<Path>

传入一个Path类型对象,之后拼接成一个字符串地址。

源码:

export function createPath({
  pathname = "/",
  search = "",
  hash = "",
}: Partial<Path>) {
  if (search && search !== "?")
    pathname += search.charAt(0) === "?" ? search : "?" + search;
  if (hash && hash !== "#")
    pathname += hash.charAt(0) === "#" ? hash : "#" + hash;
  return pathname;
}

目录

相关推荐
为什么更多前端应用偏向于单页面应用路由模式-原生historyHistory库源码分析-parsePathHistory库源码分析-Action动作类型History库源码分析-createLocation路由模式-hash