推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
xiaoming1992

react-router 为什么没有 Router 把路由信息放到请求参数里?

  •  
  •   xiaoming1992 · Oct 23, 2020 · 1411 views
    This topic created in 2052 days ago, the information mentioned may be changed or developed.

    我知道有 BrowserRouter, 路由信息直接放在路径中, 缺点是需要后端配合;

    还有 HashRouter, 路由信息放在 hash 中, 缺点是, 如果想要获取 searchParams 等参数, 需要使用 react-router-dom 导出的方法(如 useLocation 等), 或者自己写函数来解析 window.location

    那为什么没有 "QueryRouter", 把路由信息放到 search 参数中, 形如 ?__router__=/index, 这样的好处是, 想要获取 searchParams 等参数, 只需要使用

    const url = new URL(window.location)
    const { hash, searchParams } = url
    

    其他各种参数都能用原生的方法来获取或设置

    那么没有 "QueryRouter", 是出于其他什么考虑吗? 有什么缺点是我没有考虑到的? 还是说已经有了?

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2865 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 05:52 · PVG 13:52 · LAX 22:52 · JFK 01:52
    ♥ Do have faith in what you're doing.