Is there a built-in way to get the current URL without any query parameters?

前端 未结 2 1924
生来不讨喜
生来不讨喜 2021-02-02 09:01

If my URL is http://www.something.com/foo/bar/index.html?color=yellow&animal=rat, it seems as though:

  • $location.path() will return
相关标签:
2条回答
  • 2021-02-02 09:29

    Not that this eliminates the need to construct it by yourself, just another way to do the same. If you use window.location object, you can just say window.location.origin+window.location.pathname

    window.location object has

    host:"localhost.abc.com:8080"
    hostname:"localhost.abc.com"
    href:"http://localhost.abc.com:8080/quickpick/repossessions/?displayStr=Repossessions&from=%2F&page=1"(whole url)
    
    origin:"http://localhost.abc.com:8080"
    pathname:"/quickpick/repossessions/"
    port:"8080"
    protocol:"http:"
    
    0 讨论(0)
  • 2021-02-02 09:45

    As far as I'm aware you have to construct it yourself. Not that you were asking how to construct it, but for those who are wondering:

    var url = $location.absUrl().split('?')[0]
    
    0 讨论(0)
提交回复
热议问题