artch/angular-route-segment

compatiblity with $locationProvider.html5Mode(true);

Closed this issue · 8 comments

The setting

$locationProvider.html5Mode(true);

helps removing the # from Angular URLs (see, for example, https://scotch.io/quick-tips/pretty-urls-in-angularjs-removing-the-hashtag).

This doesn't seem to be entirely compatible with angular-route-segment since the latter still inserts # in all of its location expansions.

Any hints?

artch commented

the latter still inserts # in all of its location expansions

Could you explain what do you mean here? angular-route-segment doesn't use or affect the $location service.

Could you explain what do you mean here? angular-route-segment doesn't use or affect the $location
service.

Well, I see that route segment links are expanded to (e.g.) localhost/#/my/content when it should be localhost/my/content.

artch commented

Could you drop an example of how you make a link here?

see https://docs.angularjs.org/guide/$location on html5 mode section. I think that would be awesome.

artch commented

@jnuserful Of course I know what html5mode is and how it should be configured. My point is that angular-route-segment doesn't use $location at all, and hence doesn't form any links, regardless with hashbang or without. The only exception is getSegmentUrl method, but it always returns URLs without #. This is why this statement seems to be incorrect:

The latter still inserts # in all of its location expansions

And this is why I asked @nschloe to show how he is forming his link, because the issue might be there, rather than in angular-route-segment.

I'm going to close this issue without any additional info provided.

Sorry. I have little idea of how this module works, but try to have "html5mode" with the example that is in this repository and got strange behavior. You may want to try it for yourself so that you have a clearer what we mean. We just say that we would like a natural working when we enable html5mode.

artch commented

@jnuserful You can't just do html5mode(true) in that example app because it was not intended to use with html5mode. You would need to write your own example app test, or rewrite some parts of that example app like that:

  • remove # from links in the templates;
  • set up <base> tag and server-side URL rewriting accordingly, as stated in AngularJS documentation.

If you implement all the requirements from the docs, html5 mode will work well with angular-route-segment. I see no reasons why this module could cause any issues with $location usage. I've checked it with myself and it played nicely with html5mode.

it's correct. Thank you for the help and sorry for ignorance.