Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Router 1.0.0 delete query parameters on reload #2730

Closed
inkstak opened this issue May 7, 2016 · 5 comments
Closed

UI Router 1.0.0 delete query parameters on reload #2730

inkstak opened this issue May 7, 2016 · 5 comments

Comments

@inkstak
Copy link

inkstak commented May 7, 2016

Hi,
Since 1.0.0, when I'm going to a state, adding an optional query parameter and reloading the page, the query parameter disappears.

Here is an example, running with ui-router 0.2.18.

  • go to #/?foo=bar
  • the url is still #/?foo=bar
  • the console output returns :
    • window.location.hash equals #/?foo=bar
    • $location.url() equals /?foo=bar

When switching to v1.0.0-alpha.4 :

  • go to #/?foo=bar
  • the url becomes #/
  • the console output returns :
    • window.location.hash equals #/?foo=bar
    • $location.url() equals /
<!DOCTYPE html>
<html lang='fr' ng-app='app'>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.18/angular-ui-router.js"></script>
    <script>
      angular
        .module('app', ['ui.router'])
        .config(['$urlRouterProvider', '$stateProvider',
          function ($urlRouterProvider, $stateProvider) {
            $urlRouterProvider.otherwise("/");
            $stateProvider.state('search', {
              url:          "/",
              templateUrl:  "/template.html",
              controller: ['$location', function ($location) {
                console.log(window.location.hash, $location.url())
              }]
            })
          }
        ])
    </script>
  </head>
  <body>
    <div ui-view></div>
    <script id='/template.html' type='text/ng-template'>
      <div></div>
    </script>
  </body>
</html>
@christopherthielen
Copy link
Contributor

Verified, this is a regression. Thanks for the bug report

@christopherthielen
Copy link
Contributor

It looks like the fix for #1573 never merged into the 1.0 codebase.

The fix will be to set location: false for transitions that originate from a URL parse. location: false tells the transition NOT to update the location after the transition succeeds.

In the plunker, click "add query param" then click "reload". The URL should not change because the transition originated from a url parse.

Subsequent normal navigations (ui-sref, etc) will clobber the url, clearing the query string (this is how 0.2.18 works also). In the plunker, click "add query param" button, then the search2 ui-sref; query string is cleared.

http://plnkr.co/edit/j7xRtpcMEkTqhREMiCkt?p=preview

@inkstak
Copy link
Author

inkstak commented May 7, 2016

Thanks. Waiting for alpha 5.

@christopherthielen
Copy link
Contributor

alpha.5 is out

@inkstak
Copy link
Author

inkstak commented May 13, 2016

Thanks, it works just fine !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants