在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 });
}
}
网友评论