Advertisement

vue地址栏前后可输入任意字符问题

阅读量:

问题:

在地址栏中,即使在#号之前随意输入字符,仍然可以实现页面跳转并进行使用,部分接口具备可用性。然而,仍有部分接口会出现404错误。

在这里插入图片描述
在这里插入图片描述

解决方法概述

在路由拦截环节中添加该段判断逻辑:

复制代码
    // 判断#号前的地址是否正确
    let wPath = window.location.href; //页面地址
    let currentHost = wPath.substring(0,wPath.indexOf("#"));  //页面#号前的地址
    // 获取主机地址,如:http://localhost:8080/
    let realHost = window.location.protocol +"//"+window.location.host+"/"  //主机地址
    console.log(

全部评论 (0)

还没有任何评论哟~