PolymerElements / app-route

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

Can __queryParams become public? #165

Open ergo opened 7 years ago

ergo commented 7 years ago

Hello,

I'm dispatching some events in form of:

this.fire('redirect-url', {
    path: '/admin/app-resources/edit/' + response.uuid + '/' + response.resource_type
});

Now I'm receiving them in my top level document:

    handleRedirectUrl: function (event){
        console.log('handleRedirectUrl', event);
        if (event.detail.path){
            this.set('route.path', event.detail.path);
        }
        if (event.detail.params){
            this.set('route.__queryParams', event.detail.params);
        }
    }

However double underscores don't give confidence if this API should be accessed by me at all. Can we get some confirmation if it will be safe for us to use?

akc42 commented 7 years ago

@ergo A safe way to change path is to do the following

     switchPath: function(path, params) {
        window.history.pushState({}, null, this.generateUri(path,params));
        window.dispatchEvent(new CustomEvent('location-changed'));
      },

This is push the new url and then dispatch the location-changed event. <iron-location> and then in turn <app-location> see that and respond - setting up the route for <app-route>. I have this function in a behaviour which gets included in many elements. It doesn't need any centralised management (<iron-location> is in effect doing that)

Note the generatURI function just encodes the params object as query parameters and appends it to path

abdonrd commented 7 years ago

Maybe this? https://github.com/PolymerElements/app-route/issues/154

ernsheong commented 6 years ago

Isn't it supposed to be used with app-location in the form of:

  <app-location route="{{route}}" query-params="{{queryParams}}"></app-location>
  <app-route route="{{route}}" pattern="[[rootPattern]]:page" data="{{routeData}}"></app-route>
robrez commented 5 years ago

ping?

> $0.queryParams === $0.route.__queryParams
   true