URL字符串是结构化的字符串,包含多个含义不同的组成部分。解析字符串后返回的URL对象,每个属性对应字符串的各个组成部分。

    1. ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
    2. │ href │
    3. ├──────────┬──┬─────────────────────┬────────────────────────┬───────────────────────────┬───────┤
    4. │ protocol │ │ auth │ host │ path │ hash │
    5. │ │ │ ├─────────────────┬──────┼──────────┬────────────────┤ │
    6. │ │ │ │ hostname │ port │ pathname │ search │ │
    7. │ │ │ │ │ │ ├─┬──────────────┤ │
    8. │ │ │ │ │ │ │ │ query │ │
    9. " https: // user : pass @ sub.example.com : 8080 /p/a/t/h ? query=string #hash "
    10. │ │ │ │ │ hostname │ port │ │ │ │
    11. │ │ │ │ ├─────────────────┴──────┤ │ │ │
    12. │ protocol │ │ username │ password │ host │ │ │ │
    13. ├──────────┴──┼──────────┴──────────┼────────────────────────┤ │ │ │
    14. │ origin │ │ origin │ pathname │ search │ hash │
    15. ├─────────────┴─────────────────────┴────────────────────────┴──────────┴────────────────┴───────┤
    16. │ href │
    17. └────────────────────────────────────────────────────────────────────────────────────────────────┘