阅读背景:

深入了解React(十五、路由1)

来源:互联网 
!-- flowchart 箭头图标 勿删 --
/**
 * 页面路由
 * @type {string}
 */
// 跳转
window.location.href = 'https://www.baidu.com';
// 回退
history.back();


/**
 * hash 路由
 * @type {string}
 */
// 跳转【也可以用a链接】
window.location = '#hash';
// 事件:onhashchange
window.onhashchange = function () {
    console.log('current hash:', window.location.hash);
};

/**
 * h5路由
 * @type {string}
 */
// 推进一个状态
history.pushState('name', 'title', '/path');
// 替换一个状态
history.replaceState('name', 'title', '/path');
// 事件:popstate
window.onpopstate = function () {
    // 全路径
    console.log(window.location.href);
    // 绝对路径
    console.log(window.location.pathname);
    // 哈希
    console.log(window.location.hash);
    // 
    console.log(window.location.search);
};
/**
 * 



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: