Trouble switching to FlowRouter

Since FlowRouter is basically the standard now (It’s posted on the meteor guide) I’ve decided to switch on over from IronRouter, and I’m having a few issues …

First off, trying to follow with an exact copy & paste from the guide, tells me to use this code:

FlowRouter.route(’/test/:_id’, {
name: ‘Lists.show’,
action() {
BlazeLayout.render(‘App_body’, {main: ‘Lists_show_page’});
}
});

It seems that the route itself is working correctly, but when I go to the route, the “action” line throws an error:

SyntaxError: Unexpected token (

The error is thrown on the action() line… Is that incorrect syntax?

Second question: When I was searching for a solution to this problem, I noticed some people saying the many meteor packages don’t work with anything but ironrouter, such as the default accounts package? This post was from over a year ago so I’m not sure if it is outdated, but is my normal functionality going to be broken from using flow?

You might have to meteor add ecmascript for #1.

Secondly, depends on what packages you’re using, but I think things are better now than last year. accounts-ui doesn’t depend on iron-router so no worries there.

you are defining action property and passing it on to the route, so there should not any braces but ‘:’.

These days most packages should also work for FlowRouter

The code snippet your using requires the ecmascript plugin to work so… either add that or change the code so its not using those JS features:

FlowRouter.route('/test/:_id', {
   name: 'Lists.show',
   action: function() {
      BlazeLayout.render('App_body', {main: 'Lists_show_page'});
   }
});

As for the packages that are compatible with FlowRouter I can’t remember the last time this was an issue for me, so the community seems to be on top of it. If you find a plugin that doesn’t work with it, you will almost certainly find a plugin that does the same thing but with FlowRouter compatibility.

Thanks for the quick responses!

Now it seems the route itself are not working… I tried in both a new project and existing project… Not sure why?

I tried the code used at the guide here: https://github.com/kadirahq/flow-router

It says to add to lib/router/js:

FlowRouter.route(’/blog/:postId’, {
action: function(params, queryParams) {
console.log(“Yeah! We are on the post:”, params.postId);
}
});

and then suggests to navigate to /blog/my-post-id… so if I go to

http://localhost:3000/blog/my-post-id

I received "Oops, looks like there’s no route on the client or the server for url: "http://localhost:3000/blog/my-post-id."

Any idea why I’m getting this error??

I know this doesn’t exactly answer your question, but I just wanted to point out I talked a lot about migrating from IR to FR in my “Blaze to React” video series: https://www.discovermeteor.com/category/blaze-to-react/

1 Like

Sacha,

Thanks for the link! I checked that out a bit already.

My original project was actually based off of the DiscoverMeteor foundation.

Since the book has not been updated yet, I think it would be really helpful if there was a page with more solid information on how to transition the DiscoverMeteor project to Flow Router (for users without React). Been working on it this morning and while most of it seems straight forward, I’m going to have to toy around with things like the loading page, the shared controllers, and checking if the user is logged in, to see how I’m supposed to get them to work in Flow.

Would be very helpful if there was a guide (or an update to the book) based around these things! Because I am going to give React a try after switching the router over… but I have never used React and do not want to switch 2 formats at once, and did not find your series until after I began the transition.

(Edit: I went through the earlier articles and noticed that the transition to flow starts BEFORE React, so scratch much of what I said. I do think it would be helpful for a quick guide to transition users from DiscoverMeteor to Flow, but the Blaze-React series is more helpful than I thought! Thanks!)