riot / route

Simple isomorphic router
MIT License
212 stars 40 forks source link

Can't get route query using tag-based routing #104

Closed rhartzfeld closed 4 years ago

rhartzfeld commented 7 years ago

Is it possible to get the route query when using tag-based routing? In my tag's <script> block I have the following...

var route = require('riot-route/tag');

this.on('route', function() {
  var q = route.query(); // throws "TypeError: route.query is not a function"
});

... but the route object does not have a query property. I'm using CommonJS for module loading and riot-route@3.1.1.

rhartzfeld commented 7 years ago

I just discovered I'm having this issue because I was providing route via a Riot mixin. My mixin was defined as:

var route = require('riot-route/tag');

riot.mixin('routeMixin', {
  route: route
});

I believe that, due to how Riot handles mixins, the non-enumerable inherited properties of route were being lost. I changed my Mixin to the following and now it works:

riot.mixin('routeMixin', {
  getRoute: function() { return route }
});
GianlucaGuarini commented 4 years ago

Closing this issue because it's related to an old router version. Please update to the latest @riotjs/route version if you can.