PolymerElements / app-route

A modular client-side router
https://www.polymer-project.org/1.0/articles/routing.html
146 stars 66 forks source link

app-location fires 'route-changed' event twice on a single route change #173

Closed mkropf closed 5 years ago

mkropf commented 7 years ago

Description

Example usage:

<dom-module id="client-component">
  <template>
    <app-location id="loc" route="{{_route}}" use-hash-as-path></app-location>
    <p><a href="#test">test</a></p>
  </template>
  <script>
    window.addEventListener('WebComponentsReady',function(){Polymer({
      is: 'client-component',
      ready: function(){
        this.$.loc.addEventListener('route-changed',function(e){
          console.log(e.detail)
        });
      }
    })});
  </script>
</dom-module>

Expected outcome

Clicking the link or changing the browser address should log a single event.

Actual outcome

The event is fired twice.

Analysis

Finding the cause in debugger showed that the property-changed effect is registered twice and therefore triggered twice when the route property changed. The cause for the duplicated effect registration is the fact that app-location declares the 'route' property and has the AppRouteConverterBehavior, which in turn also declares the 'route' property. (You may see it as a app-location bug or as polymer core bug)

Niklas2908 commented 7 years ago

In my case the app-location fires once on the first route but twice for every following route back to the page.

diwalkerdev commented 7 years ago

Related/duplicated: https://github.com/PolymerElements/app-route/issues/178

lauritowal commented 6 years ago

For me, this happens only when the path has parameters like /path?parameter=test

mkropf commented 5 years ago

outdated, nobody caring anymore

danleyb2 commented 4 years ago

@mkropf this issue still exist