kadirahq / flow-router

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

Going to new route the page reloads on it's own and goes back to previous page #713

Closed daryl-williams closed 4 years ago

daryl-williams commented 7 years ago

Hello folks, I am new to flow-router and Meteor and I am trying to narrow down where the problem might be. The problem is this: On clicking a button I want the browser to go to a new page, which it does ok, but then it immediately returns to the previous page with any user interaction. I am not sure that this is a flow-router issue, but as I said I am trying to figure out where the problem is and the router seems like a good place to start.

The app is pretty basic, there are just two pages, the first page contains a list of text files with song names represented by an un-ordered list and a second page to display the song when it is selected by clicking on the

  • element. When the user selects a song it triggers a click event that runs a server method to process the song selection by running an external command an then returns the output to the calling event handler which then runs: FlowRouter.go('/song/' + song_name) to change pages. The browser navigates to the new page, but immediately returns to the previous dashboard page with the song list.

    Following are my routes as defined in the client/routes.js file:

    Accounts.onLogin(function () { FlowRouter.go('/dashboard'); })

    FlowRouter.route('/dashboard', { name: 'dashboard', action: function(params, queryParams) { console.log('/lib/routes.js: Page = /dashboard'); BlazeLayout.render("Members", {memberContent: "Dashboard"}); } });

    FlowRouter.route('/song/:name', { name: 'song', action: function(pathParams, queryParams) { console.log('/lib/routes.js: Page = /song/:name');; BlazeLayout.render("Members", {memberContent: "SongPage"}); }, });

    Here are my Templates:

    and here are the template helpers:

    Template.Members.helpers({ 'getTemplateName': function() { var route = FlowRouter.getRouteName(); if (route === 'dashboard') { template = 'Dashboard'; } else if (route === 'song') { template = 'SongPage'; } else { template = 'Dashboard'; } return template; }, });

    Template.SongPage.helpers({ 'getSong': function() { var currentSong = Session.get('currentSong'); return (currentSong !== undefined) ? Spacebars.SafeString(currentSong) : ''; } }, });

    Any and all help would be much appreciated. If I can provide any further information please let me know. I really need to nail down if the problem is with the routing or some other newbie mistake.

    Thanks and Regards,

    Daryl

  • Jarskih commented 7 years ago

    I can confirm I have same issue.

    I am using helper : {{#if isUpvoted}} Show template A {{else}} Show template B {{/if}}

    After user upvotes and helper changes to "true" it the page will refresh the new template then immediately go back to previous template and helper suddenly returns "false". The upvote is correctly changed in MongoDB. Only page force refresh shows the correct template. And I recently updated app from 1.2.1 Meteor to latest 1.4. Also updated Flowrouter to latest version.

    I could fix some problems with FlowRouter.refresh() maybe you can try that after click event?