Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlowRouter._routes contain routes but I still get route undefined erro #710

Open
NvdB31 opened this issue Dec 28, 2016 · 1 comment
Open

Comments

@NvdB31
Copy link

NvdB31 commented Dec 28, 2016

I'm looking to initialise routes from pages that are defined in a database collection. So I made the following:

FlowRouter.wait();

Meteor.subscribe("pages", {
	onReady: function () {
		const allPages = Pages.find().fetch();

	for (var i = 0; i < allPages.length; i++) {
		FlowRouter.route('/'+allPages[i].slug, {
		    name: allPages[i].name,
		    action: function(params, queryParams) {

		    }
		});
	};
	}
});

FlowRouter.initialize();

Then when I open up the browser console I can see that the FlowRouter._routes object contains a nice array with all the routes from the collection. However when I visit the routes I get an error: 'There is no route for the path: routename'

Any ideas why this is happening? It seems that it cannot initialise routes from within a loop so it seems?

@ziedmahdi
Copy link

@cloudrocketsoftware put FlowRouter.initialize(); inside the onReady callback, at the end.

FlowRouter.wait();

Meteor.subscribe("pages", {
    onReady() {
        Pages.find().forEach(function (page) {
            FlowRouter.route('/' + page.slug, {
                name: page.name,
                action: function (params, queryParams) {

                }
            });
        });

        FlowRouter.initialize();
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants