Vue有两种路由模式:hash,history

(1)hash模式

通过监听路由的变化实现,如下代码.路由中带着#,变化的也都是#后面的值

window.onhashchange = function(event) {
    console.log(event.oldURL, event.newURL);
    let hash = loaction.hash  //通过location对象来获取hash地址
    console.log(hash)    // "#/notebooks/260827/list"  从#号开始
}

(2)history模式

url中没有#,是全地址,所以刷新页面的时候会根据全地址取请求后台,后台也需要做对应的处理,否则页面请求不到就会404

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-21
  • 2021-12-14
  • 2021-11-23
  • 2022-12-23
  • 2021-10-21
  • 2022-12-23
猜你喜欢
  • 2021-12-15
  • 2022-12-23
  • 2021-08-13
  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案