Flow-Router doesn’t seem to work at all. I added a folder named “lib” and added a file named “router.js”. Below is my simple Router code. If I try to go to another page other than the index page, nothing happens. It doesn’t route to another page at all. I don’t even get an error.
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
// DISABLE QUERY STRING COMPATIBILITY
// WITH OLDER FlowRouter AND Meteor RELEASES
FlowRouter.decodeQueryParamsOnce = true;
FlowRouter.route('/', {
name: 'main',
action() {
// Render a template using Blaze
this.render('main');
// Can be used with BlazeLayout,
// and ReactLayout for React-based apps
}
});
// Create 404 route (catch-all)
FlowRouter.route('*', {
action() {
// Show 404 error page using Blaze
this.render('notFound');
// Can be used with BlazeLayout,
// and ReactLayout for React-based apps
}
});
Hey @trustydusty82, I’m not sure what the structure of your project is, but if you just generated it, you should have something like:
/client
main.css
main.html
main.js
/lib
router.js
/server
main.js
Have you imported your lib/router.js
file into your client/main.js
?
The routing problem could be caused by missing imports, incorrect route definitions, navigation code issues, etc. Could you share more details on your project?
1 Like
Thanks I realized I had imported it in the wrong main.js file. I built a whole app in the previous version of Meteor without ever having to import anything. I assume there was a package handling that before? Is there anything like that in Meteor 3 and Blaze?
2 Likes
Using imports
gives you explicit control over which JS files load and when, while Meteor’s legacy system loads everything automatically in a hard-to-predict order that often causes confusion and bugs as your app grows.
If you want Meteor to import everything without explicit imports, you can remove the module definition from your package.json
.
{
"meteor": {
"mainModule": {
"client": "client/main.js",
"server": "server/main.js"
},
"testModule": "tests/main.js"
}
}
By removing this, Meteor will use its legacy file loading system. Also works in Meteor 3.0.
1 Like