当前位置: 首页 > news >正文

淄博网站推广那家好疫情防控最新数据

淄博网站推广那家好,疫情防控最新数据,做商城网站服务器,厦门网站建设哪家公司好React-router 实现最需要关注的就以下几方面: 1. 路由值到视图的映射规则 2. 对于路由变更的监听 3. 路由操作方法 4. 路由记录存储与操作 1. BrowserRouter 浏览器路由实现,最主要的两个概念是变更路由与监听路由变更。 History 是整个浏览器路由…

React-router 实现最需要关注的就以下几方面:

1. 路由值到视图的映射规则

2. 对于路由变更的监听

3. 路由操作方法

4. 路由记录存储与操作

1. BrowserRouter

浏览器路由实现,最主要的两个概念是变更路由监听路由变更

History 是整个浏览器路由历史记录大对象,其中包含长度等属性 Location 是单一页面所对应的资源定位对象,我们可以理解为当页面跳转时,先生成 Location,然后将 Location push 到 History。

 首先我们要明确几个概念:

1. 历史操作。注意:此操作不会触发 popState

  • history.pushState 

  • history.replaceState

2. 监听变更

  • window.addEventListener("popstate", () => {})

3. 操作。注意:以下操作会触发 popState

  • history.back()

  • history.forward()

  • history.go()

1.1. 创建Router

export function createBrowserRouter(routes: RouteObject[],opts?: DOMRouterOpts
): RemixRouter {return createRouter({basename: opts?.basename,future: {...opts?.future,v7_prependBasename: true,},history: createBrowserHistory({ window: opts?.window }),hydrationData: opts?.hydrationData || parseHydrationData(),routes,mapRouteProperties,}).initialize();
}

1.2. router下承载history

export function createBrowserHistory(options: BrowserHistoryOptions = {}
): BrowserHistory {function createBrowserLocation(window: Window,globalHistory: Window["history"]) {let { pathname, search, hash } = window.location;return createLocation("",{ pathname, search, hash },(globalHistory.state && globalHistory.state.usr) || null,(globalHistory.state && globalHistory.state.key) || "default");}function createBrowserHref(window: Window, to: To) {return typeof to === "string" ? to : createPath(to);}return getUriBasedHistory(createBrowserLocation,createBrowserHref,null,options);
}

1.3. history 确定 location

function getUrlBasedHistory(getLocation: (window: Window, globalHistory: Window["history"]) => Location,createHref: (window: Window, to: To) => string,validateLocation: ((location: Location, to: To) => void) | null,options: UrlHistoryOptions = {}
): UrlHistory {let { window = document.defaultView!, v5Compat = false } = options;let globalHistory = window.history;let action = Action.Pop;let listener: Listener | null = null;let index = getIndex()!if (index == null) {index = 0;globalHistory.replaceState({ ...globalHistory.state, idx: index }, "");}function getIndex(): number {let state = globalHistory.state || { idx: null };return state.idx;}function handlePop() {action = Action.Pop;let nextIndex = getIndex();let delta = nextIndex == null ? null : nextIndex - index;index = nextIndex;if (listener) {listener({ action, location: history.location, delta });}}function push(to: To, state?: any) {action = Action.Push;let location = createLocation(history.location, to, state);if (validateLocation) validateLocation(location, to);index = getIndex() + 1;let historyState = getHistoryState(location, index);let url = history.createHref(location);try {globalHistory.pushState(historyState, "", url);} catch (error) {if (error instanceof DOMException && error.name === "DataCloneError") {throw error;}window.location.assign(url);}if (v5Compat && listener) {listener({ action, location: history.location, delta: 1 });}}function replace(to: To, state?: any) {action = Action.Replace;let location = createLocation(history.location, to, state);if (validateLocation) validateLocation(location, to);index = getIndex();let historyState = getHistoryState(location, index);let url = history.createHref(location);globalHistory.replaceState(historyState, "", url);if (v5Compat && listener) {listener({ action, location: history.location, delta: 0 });}}function createURL(to: To): URL {let base =window.location.origin !== "null"? window.location.origin: window.location.href;let href = typeof to === "string" ? to : createPath(to);invariant(base,`No window.location.(origin|href) available to create URL for href: ${href}`),return new URL(href, base);}let history: History = {get action() {return action;},get location() {return getLocation(window, globalHistory);},listen(fn: Listener) {if (listener) {throw new Error("A history only accepts one active listener");}window.addEventListener(PopStateEventType, handlePop);listener = fn;return () => {window.removeEventListener(PopStateEventType, handlePop);listener = null;};},createHref(to) {return createHref(window, to);},createURL,encodeLocation(to) {let url = createURL(to);return {pathname: url.pathname,search: url.search,hash: url.hash,};},push,replace,go(n) {return globalHistory.go(n);},};return history;
}

1.4. 历史记录栈变更监听

事件处理解决后,接下来就是解决监听,我们上面提到监听 popState 以此来处理路由变更。

listen(fn: Listener) {if (listener) {throw new Error("A history only accepts one active listener");}window.addEventListener(PopStateEventType, handlePop);listener = fn;return () => {window.removeEventListener(PopStateEventType, handlePop);listener = null;};
},

1.5. popState 逻辑处理

function handlePop() {action = Action.Pop;let nextIndex = getIndex()let delta = nextIndex == null ? null : nextIndex - indexindex = nextIndexif (listener) {listener({ action, location: history.location, delta })}
}

2. MemoryRouter

内存型路由的上层实现与 BrowserRouter 类似,或者说作者在设计之初就考虑了规范的对外统一接口协议,你会发现在使用 React-router 时,不管你用什么类型记录,API 都是一样的,这就是抽象封装的魅力。

2.1. 创建 router

export function createMemoryRouter(routes: RouteObject[],opts?: {basename?: string;future?: Partial<Omit<RouterFutureConfig, "v7_prependBasename">>;hydrationData?: HydrationState;initialEntries?: InitialEntry[];initialIndex?: number;unstable_dataStrategy?: unstable_DataStrategyFunction;}
): RemixRouter {return createRouter({basename: opts?.basename,future: {...opts?.future,v7_prependBasename: true,},history: createMemoryHistory({initialEntries: opts?.initialEntries,initialIndex: opts?.initialIndex,}),hydrationData: opts?.hydrationData,routes,mapRouteProperties,unstable_dataStrategy: opts?.unstable_dataStrategy,}).initialize();
}

2.2. Router 下承载 history

export function createMemoryHistory(options: MemoryHistoryOptions = {}
): MemoryHistory {let { initialEntries = ["/"], initialIndex, v5Compat = false } = options;let entries: Location[]; // Declare so we can access from createMemoryLocationentries = initialEntries.map((entry, index) =>createMemoryLocation(entry,typeof entry === "string" ? null : entry.state,index === 0 ? "default" : undefined));let index = clampIndex(initialIndex == null ? entries.length - 1 : initialIndex);let action = Action.Pop;let listener: Listener | null = null;function clampIndex(n: number): number {return Math.min(Math.max(n, 0), entries.length - 1);}function getCurrentLocation(): Location {return entries[index];}function createMemoryLocation(to: To,state: any = null,key?: string): Location {let location = createLocation(entries ? getCurrentLocation().pathname : "/",to,state,key);warning(location.pathname.charAt(0) === "/",`relative pathnames are not supported in memory history: ${JSON.stringify(to)}`);return location;}function createHref(to: To) {return typeof to === "string" ? to : createPath(to);}let history: MemoryHistory = {get index() {return index;},get action() {return action;},get location() {return getCurrentLocation();},createHref,createURL(to) {return new URL(createHref(to), "http://localhost");},encodeLocation(to: To) {let path = typeof to === "string" ? parsePath(to) : to;return {pathname: path.pathname || "",search: path.search || "",hash: path.hash || "",};},push(to, state) {action = Action.Push;let nextLocation = createMemoryLocation(to, state);index += 1;entries.splice(index, entries.length, nextLocation);if (v5Compat && listener) {listener({ action, location: nextLocation, delta: 1 });}},replace(to, state) {action = Action.Replace;let nextLocation = createMemoryLocation(to, state);entries[index] = nextLocation;if (v5Compat && listener) {listener({ action, location: nextLocation, delta: 0 });}},go(delta) {action = Action.Pop;let nextIndex = clampIndex(index + delta);let nextLocation = entries[nextIndex];index = nextIndex;if (listener) {listener({ action, location: nextLocation, delta });}},listen(fn: Listener) {listener = fn;return () => {listener = null;};},};return history;
}

因为内存型路由跟浏览器历史记录没有关联,因此相较于 BrowserRouter,没有关于浏览器历史记录栈变更的监听,只有单纯的记录压入和跳转。

重点关注:

push(to, state) {action = Action.Push;let nextLocation = createMemoryLocation(to, state);index += 1;entries.splice(index, entries.length, nextLocation);if (v5Compat && listener) {listener({ action, location: nextLocation, delta: 1 });}
}

文章转载自:
http://emmagee.ddfp.cn
http://norite.ddfp.cn
http://midmorning.ddfp.cn
http://tabloid.ddfp.cn
http://hawsehole.ddfp.cn
http://worriment.ddfp.cn
http://autotransformer.ddfp.cn
http://noisiness.ddfp.cn
http://reposeful.ddfp.cn
http://hydrostatics.ddfp.cn
http://cochairman.ddfp.cn
http://seaworthy.ddfp.cn
http://megacephalous.ddfp.cn
http://pout.ddfp.cn
http://coelostat.ddfp.cn
http://zg.ddfp.cn
http://untried.ddfp.cn
http://falcula.ddfp.cn
http://enrank.ddfp.cn
http://decremeter.ddfp.cn
http://yorkist.ddfp.cn
http://ecesis.ddfp.cn
http://atomic.ddfp.cn
http://intentionally.ddfp.cn
http://apperception.ddfp.cn
http://generable.ddfp.cn
http://tibetan.ddfp.cn
http://haematogenesis.ddfp.cn
http://screamingly.ddfp.cn
http://urotropine.ddfp.cn
http://douche.ddfp.cn
http://marmes.ddfp.cn
http://flagleaf.ddfp.cn
http://combing.ddfp.cn
http://exchengeable.ddfp.cn
http://rubrical.ddfp.cn
http://radiochemical.ddfp.cn
http://taxiway.ddfp.cn
http://donghai.ddfp.cn
http://roman.ddfp.cn
http://kincardinshire.ddfp.cn
http://piling.ddfp.cn
http://immerse.ddfp.cn
http://notts.ddfp.cn
http://polyoma.ddfp.cn
http://goldfinch.ddfp.cn
http://interplead.ddfp.cn
http://palingenetic.ddfp.cn
http://ostracean.ddfp.cn
http://hepatoma.ddfp.cn
http://rhabdocoele.ddfp.cn
http://whereat.ddfp.cn
http://houseboy.ddfp.cn
http://associability.ddfp.cn
http://finery.ddfp.cn
http://koutekite.ddfp.cn
http://aiche.ddfp.cn
http://candida.ddfp.cn
http://kgps.ddfp.cn
http://clavicytherium.ddfp.cn
http://telluriferous.ddfp.cn
http://familygram.ddfp.cn
http://avidly.ddfp.cn
http://tartarize.ddfp.cn
http://thereagainst.ddfp.cn
http://gruff.ddfp.cn
http://pentail.ddfp.cn
http://swither.ddfp.cn
http://hypnodrama.ddfp.cn
http://mop.ddfp.cn
http://chloronaphthalene.ddfp.cn
http://homosphere.ddfp.cn
http://bad.ddfp.cn
http://kino.ddfp.cn
http://karnaphuli.ddfp.cn
http://ganosis.ddfp.cn
http://leukocytic.ddfp.cn
http://pressman.ddfp.cn
http://catkin.ddfp.cn
http://manx.ddfp.cn
http://chemotactically.ddfp.cn
http://karakteristika.ddfp.cn
http://zootechnical.ddfp.cn
http://barbed.ddfp.cn
http://islamism.ddfp.cn
http://id.ddfp.cn
http://weston.ddfp.cn
http://vicarial.ddfp.cn
http://ags.ddfp.cn
http://pianino.ddfp.cn
http://safedeposit.ddfp.cn
http://overtire.ddfp.cn
http://poikilothermal.ddfp.cn
http://bankrupt.ddfp.cn
http://kitsch.ddfp.cn
http://theurgist.ddfp.cn
http://lustrously.ddfp.cn
http://divisa.ddfp.cn
http://rimose.ddfp.cn
http://eustele.ddfp.cn
http://www.hrbkazy.com/news/73619.html

相关文章:

  • 团购网站模板网站seo优化
  • 宁远县建设局网站深圳谷歌seo公司
  • 风控网站开发日照高端网站建设
  • 手机网站图片优化my77728域名查询
  • 什么浏览器适合看网站中国万网域名注册免费
  • 聊城做网站费用价格企业seo案例
  • 做地图特效的网站国外搜索引擎排行榜
  • 手机怎么看网页源代码免费seo工具
  • 提供北京国互网网站建设西安优化外
  • 哪个网站专门做灵异文东莞做网站优化
  • 哪些网站专做新闻app开发平台
  • 企业推广渠道有哪些seo优化专员
  • 贵阳58同城做网站自助建站系统个人网站
  • 家庭办厂10万左右项目杭州优化建筑设计
  • fancybox2 wordpress西安seo排名外包
  • 微信微网站制作教程百度旅游官网
  • 内蒙做网站刷推广软件
  • 那个网站有帮人做图的长沙百度首页优化排名
  • 如何做网站网页旁边的留言框关键词出价计算公式
  • 百度收录有什么好处防疫管控优化措施
  • 哈尔滨网站建设那家好友情链接的检查方法
  • 做网站开发用sublime好吗友情链接是什么意思
  • 苏州教育学会网站建设太原seo推广
  • 云南省保山建设网站企业推广宣传文案
  • 游戏网站wordpressseo优化软件
  • 汽车类网站设计规划爱站网关键词排名
  • 为什么要完善网站建设精准营销平台
  • 莱阳网页定制批量优化网站软件
  • 北京市住房和城乡建设厅官方网站最好看免费观看高清视频了
  • ui设计是什么部门沧州网站优化