I need to extract the path before the # in my AngularJS app, so for example if my app url is:
http://www.domain.com/folder/app/#/home
I need to get only this portion:
http://www.domain.com/folder/app/
I've tried using $location.path, $location.abspath but couldn't find any function that can get me the first portion before the #. Can someone please help me by telling me what I am missing here? and if there is a way to get the first portion of the url (before the #)? Thanks
You could split the path into the pathname and hash parts, and then use the pathname only:
$location.absUrl().split('#')[0]
// "http://www.example.com/folder/app/"
split
is just a Javascript string operation returning an array:
'http://www.example.com/folder/app/#/home'.split('#')
["http://www.example.com/folder/app/", "/home"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With