Vue -- Vue-Router

在这里插入图片描述
原文链接

一、路由模式:

  • Hash

    • 浏览器刷新与页面跳转
      1. hash是页面中快速定位的对应Id锚点的方式;
      2. location.hash可获取hash值;
      3. location.assignlocation.replace可以修改hash值;
    • 监听路由变化
      1. 浏览器提供了一个hashchange事件
      2. 使用onhashchange的全局函数
      3. 使用addEventListen(‘hashchange’, fn)
  • History(HTML5)

    • 浏览器刷新与页面跳转
      • html5对history进行了拓展,提供了两个新的API,来修改URL时不会刷新浏览器页面
        1. history.pushState:对应上面的location.assign
        2. history.replaceState:对应上面的location.replace
    • 监听路由变化
      1. 使用popstate事件来监听
      2. onPopState事件,同上
  • Memory

    • 不会自动触发初始路由
    • 适合SSR,不会有历史记录

二、路由守卫

全局

    猜你喜欢

    转载自blog.csdn.net/weixin_40240616/article/details/140786273