美文网首页
web history分析

web history分析

作者: 苏鑫的博客 | 来源:发表于2019-06-01 13:50 被阅读0次

在react-router使用过程中
好奇其单页是如何不刷新页面的


        if (canUseHistory) {
          globalHistory.pushState({ key, state }, null, href); //html5的api 改变href不改变页面

          if (forceRefresh) {
            window.location.href = href;//刷新页面,发起加载页面请求
          } else {
            const prevIndex = allKeys.indexOf(history.location.key);
            const nextKeys = allKeys.slice(
              0,
              prevIndex === -1 ? 0 : prevIndex + 1
            );

            nextKeys.push(location.key);
            allKeys = nextKeys;

            setState({ action, location });
          }
        }

相关文章

网友评论

      本文标题:web history分析

      本文链接:https://www.haomeiwen.com/subject/woaotctx.html