kadirahq / flow-router

Carefully Designed Client Side Router for Meteor
MIT License
1.09k stars 193 forks source link

[ssr] .go(), .getQueryParam() retuns undefined in constructor #572

Open chmac opened 8 years ago

chmac commented 8 years ago

We have a search form on the homepage. The user enters some value, we store that in the component's state. Then the user clicks Submit and we do:

FlowRouter.go('route', null, {foo: 'bar'})

Then in the component that's rendered by route we do this:

constructor() {
  let foo = FlowRouter.getQueryParam('foo')
}

In this case, foo is undefined. The result of getQueryParam() is undefined at that point. Likewise in the componentDidMount() callback. This was not the case with flow-router, only once we changed to flow-router-ssr to workaround #379.

chmac commented 8 years ago

Maybe I should add, if I call FlowRouter.go() from the console, the problem does not happen. We're calling it from a submit button's onClick() callback, and then the problem happens.

Also, the browser's address bar has already updated by the time that the FlowRouter.getQueryParam() call returns undefined so we could probably workaround by reading window.location, although that seems pretty ugly...

chmac commented 8 years ago

Further investigation shows that FlowRouter.current().queryParams.foo has the correct value, but somehow .getQueryParam() returns undefined. At least we have an easy workaround...

tjcampbell commented 8 years ago

Having the same issue after changing to flow-router-ssr. Thanks your workaround saved me some digging.