kadirahq / flow-router

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

FlowRouter.go() vs FlowRouter.redirect() #473

Closed avalanche1 closed 8 years ago

avalanche1 commented 8 years ago

Hi, @arunoda ! I have these routes:

FlowRouter.route("/", {
  name: 'home',
  action: function() {
    return FlowRouter.go("/postList/" + getUserCityId());
  }
});

FlowRouter.route("/postList/:cityId", {
    name: 'postList',
    action: function() {
      return BlazeLayout.render('mainLayout', {
        top: 'header',
        body: 'body'
      });
  }
});

If I click a home link in any other route, browser will render 'postList' route correctly, but the url will flash /postList/someCityId and then become only / (or localhost:3000).

But if I use undocumented FlowRouter.redirect("/postList/" + getUserCityId()) instead of FlowRouter.go() - everything works as expected, the url is correct: /postList/someCityId.

May also be linked to https://github.com/kadirahq/flow-router/issues/351

arunoda commented 8 years ago

Yep. We have some issues while trying to change the route while routing.

Sometimes redirect works. We have a proper fix in version 4. On 2016 ජන 7, බ්‍රහස් at ප.ව. 8.10 Artem Saffron notifications@github.com wrote:

Hi, @arunoda https://github.com/arunoda ! I have these routes:

FlowRouter.route("/", { name: 'home', action: function() { return FlowRouter.go("/postList/" + getUserCityId()); } });

FlowRouter.route("/postList/:cityId", { name: 'postList', action: function() { return BlazeLayout.render('mainLayout', { top: 'header', body: 'body' }); } });

If I click a home link in any other route, browser will render 'postList' route correctly, but the url will flash /postList/someCityId and then become only / (or localhost:3000).

But if I use undocumented FlowRouter.redirect("/postList/" + getUserCityId()) instead of FlowRouter.go() - everything works as expected, the url is correct: /postList/someCityId.

May also be linked to #351 https://github.com/kadirahq/flow-router/issues/351

— Reply to this email directly or view it on GitHub https://github.com/kadirahq/flow-router/issues/473.

avalanche1 commented 8 years ago

When v4 is due?

arunoda commented 8 years ago

End of this month.

On Fri, Jan 8, 2016 at 10:52 AM Artem Saffron notifications@github.com wrote:

When v4 is due?

— Reply to this email directly or view it on GitHub https://github.com/kadirahq/flow-router/issues/473#issuecomment-169899254 .

mjgallag commented 8 years ago

@avalanche1 @arunoda I just experienced this exact same problem and was in the middle of logging a detailed issue, but, better late than never to find this exchange. Using undocumented FlowRouter.redirect in place of FlowRouter.go seems to work for me too.

There were 3 use cases I could distinguish, user gets logged out while viewing a page that requires login, a logged out user visits a page that requires login via their browser's address bar, a logged out user visits a page that requires login via a relative hyperlink (or execute's a FlowRouter.go). FlowRouter.go worked for the first 2 use cases, but not the last one. FlowRouter.redirect worked for all 3 use cases.

@arunoda when version 4 arrives will this all work with FlowRouter.go or will FlowRouter.redirect be the documented approach for this scenario? Thanks!