在react-router使用過(guò)程中
好奇其單頁(yè)是如何不刷新頁(yè)面的
if (canUseHistory) {
globalHistory.pushState({ key, state }, null, href); //html5的api 改變href不改變頁(yè)面
if (forceRefresh) {
window.location.href = href;//刷新頁(yè)面,發(fā)起加載頁(yè)面請(qǐng)求
} 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 });
}
}