RafaelVidaurre / angular-permission

Simple route authorization via roles/permissions
MIT License
1.13k stars 212 forks source link

Search params not preserved on page refresh when using permission.ui module #401

Closed sagrawal31 closed 7 years ago

sagrawal31 commented 7 years ago

First of all, amazing library! πŸ‘ I started developing a separate module for role based security for client side but then I found this library and stopped development of that πŸ˜„

I'm using angular 1.5.8, angular-ui-router 0.2.18 & 5.1.0 version of this library. I have enabled the HTML5 mode in the app. Everything was working fine in my app until today when I starting making use of $location.search() method.

My module is including dependencies as:

angular.app('app', [
    ...
   'ui.router',
   'permission', 'permission.ui', 
   ...
]);

I have a simple user listing page with various filters. I'm changing the app so that whenever filter changes, I set it on the URL (so that user can share the URL with applied filters), for example $location.search({query: 'john', sort: 'email'}). This is working fine and the URL is getting changed from http://localhost:9000/user/list to http://localhost:9000/user/list?query=john&sort=email when filter changes.

But when I'm refreshing the page, the query params are getting removed and URL is being changed to http://localhost:9000/user/list. I have been searching the cause for this issue the whole day and gone through various GitHub issues of Angular, ui-router and SO posts but nothing helped me.

Then I started trial & error and removed this library module completely and things started working fine. I researched more and found out that it's actually the permission.ui module that is causing this problem so if I just remove the permission.ui module from the app, that query string persists on refreshing the page.

I don't understand how thepermission.ui module is making that issue and what is the fix for that.

sagrawal31 commented 7 years ago

Actually, I figured out. This is because of location: true here https://github.com/Narzerus/angular-permission/blob/master/dist/angular-permission-ui.js#L138

sagrawal31 commented 7 years ago

But what is the use of location: true there?

sagrawal31 commented 7 years ago

@masterspambot here is the commit that changed location: 'replace' to location: true https://github.com/Narzerus/angular-permission/commit/3ea0e9e05221efa8fa81aab6748487c2f7656ad8 for issue #229. Even location: true is not needed here (as much as I understand). If someone wants to set any value for location then they can always use TransitionProperties.options.

masterspambot commented 7 years ago

Sorry but it can't. For sure try I even tried to run it today without flag set. Then the history is empty (try to navigate back in broswer).

sagrawal31 commented 6 years ago

Hi @masterspambot so what can be the alternative to achieve both the use-cases? Can you please suggest some