url解析

 1  <script>
 2     (function(window) {
 3       window.addEventListener('hashchange', function(e) {
 4         var hash = window.location.hash;
 5         switch (hash) {
 6           case '#/index/':
 7             console.log('请求index');
 8             break;
 9           case '#/demo/':
10             console.log('demo');
11             break;
12           case '#/aaa/':
13             console.log('aaa');
14             break;
15         }
16         // console.log(11111);
17         // console.log(e);
18         // hash 属于路径(URL)的组成
19         // console.log(window.location);
20         // 可以通过 window.location 拿到所有信息
21 
22         // https://www.baidu.com:8080/aaa/1.html?id=10#name
23         //
24         // protocol: https
25         // host: www.baidu.com:8080
26         // hostname: www.baidu.com
27         // port: 8080
28         // pathname: /aaa/1.html
29         // search: ?id=10
30         // hash: #name
31       });
32     })(window);
33   </script>
原文地址:https://www.cnblogs.com/yangguoe/p/8507960.html