window.location.search为空原因

博客: https://lonhon.top/

例1: 'http://a.a.com/data?id=1&time=2018-06-07'

此时通过 window.location.search 能够正常获取到url中的查询参数 id=1&time=2018-06-07

例2:'http://a.a.com/#/data?id=1&time=2018-06-07'

此时通过 window.location.search 获取到的参数为空"",这是因为使用了hash导致,因为hash会将url中第一个#后的内容都作为hash内容,所以search为空了.

解决办法: 通过处理location.hash来获取query.

posted @ 2018-06-07 11:32  游龙翔隼  阅读(3246)  评论(0编辑  收藏  举报