http://127.0.0.1:8080/index.php?id=123123/#!/filter?page=1
为什么这样的网址$route.query
会解析出{id: 123123, page: 1}
而不是仅仅解析"#!
"后面的{page: 1}
vue-router有api只解析"#!"后面的吗? (我知道window.location.hash能获取到"#!"后的字符串。)
这是因为在vue-router
里有一个对URL处理的特殊过程:
// determine query
// note it's possible to have queries in both the actual URL
// and the hash fragment itself.
const query = location.search && path.indexOf('?') > -1
? '&' + location.search.slice(1)
: location.search
self.onChange(path.replace(/^#!?/, '') + query)
源码地址:vue-router
她的作用就是从URL里,把#!
之前的?
部分取出来,然后拼到了URL的后面。