If I hit the url say
www.xyz.com/home#route-1
AngularJS automatically re-directs it to
www.xyz.com/home#/route-1
That is - it prefixes the route with a /
(forward slash)
Why is it happening and how can I stop making it do this?
Update What I am really looking for is that angular should not attach the forward slash neither remove the hash sign.
In HTML5 mode, the $location service getters and setters interact with the browser URL address through the HTML5 history API. This allows for use of regular URL path and search segments, instead of their hashbang equivalents.
The $location in AngularJS basically uses a window. location service. The $location is used to read or change the URL in the browser and it is used to reflect that URL on our page. Any change made in the URL is stored in the $location service in AngularJS.
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.
A reference to the browser's window object. While window is globally available in JavaScript, it causes testability problems, because it is a global variable. In AngularJS we always refer to it through the $window service, so it may be overridden, removed or mocked for testing.
@Tushar I'm not sure if you've figured out a solution but I came across your scenario too and no luck with googling. Eventually I figured out it's a rather simple fix, I've added : -
angular.config(function($locationProvider) {
$locationProvider.html5Mode({
enabled: true,
requireBase: false,
rewriteLinks: false
});
})
And it just stop appending the forward slash (/) prefix to my hash anchor. Everything remains as what we're familiar with (no replacing of URL with hash or what-not).
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