so $location.path is www.abc.com/portal and host is www.abc.com I am trying to set the location as www.abc.com
$location.path($location.host);
so $location.path is www.abc.com/portal and host is www.abc.com I am trying to set the location as www.abc.com
$location.path($location.host);
On
Because you need to redirect to main route. So try $location.path("/"); it add string after your $location.host();
For example:
// suppose $location.host = 'www.abc.com'
$location.path('/example')
// redirect to 'www.abc.com/#/example'
$location.path('/')
// redirect to your "otherwise" [route][1] if '/' isn't define 'www.abc.com/#/'
See documentation here:
This method is getter / setter.
Return path of current URL when called without any parameter.
Change path when called with parameter and return $location.
Note: Path should always begin with forward slash (/), this method will add the forward slash if it is missing.
On
I was trying to change the entire url means from www.abc.com/portal to www.abc.com
It works with
$location.href = location.origin;
Because location.host only contains
www.abc.com
and that was going to concatinate with
www.abc.com/portal/www.abc.com
using location.origin I was getting
https:// www.abc.com
so It is redirecting now.
I think you'll have to use $scope.$apply() after setting
$location.path()inorder to make that work.