Flow Router and pathFor Assistance

Hi All,

I’m trying to display a simple landing/home page and then link to other pages, e.g. FAQ, About Us, etc. using FlowRouter as well as the helpers package but I keep getting a blank page. Please assist

client/lib/routes.js:

FlowRouter.route('/', {
name: 'Landing',
action() {
    BlazeLayout.render('LandingLayout');
}
});

FlowRouter.route('/faq', {
name: 'faq',
action() {
    BlazeLayout.render('MainLayout', {main: 'FAQ'});
}
});

client/layouts/LandingLayout.html:

<template name="Landing">

<body>
<header>
</header>
<main>

Usual code found on landing pages, including - <p><a href="{{path For '/faq/'}}">FAQ</a></p>

</main>
</body>
</template>

client/layouts/MainLayouts.html:

<template name="MainLayout">
 <header>
 </header>
 <main>
    {{> Template.dynamic template=main}}
 </main>
</template>

client/faq.html:

<template name="FAQ">

<head>

<title> </title>


</head>

<body>


"Some Content"

 </body>

</template>

You can use triple backticks to format your code. Or else link to a GitHub gist.

So I’m thinking your BlazeLayout.render('LandingLayout') should be BlazeLayout.render('Landing'), which matches your template name.

Code has been corrected to display properly now. Please comment as to weather my pathFor is correct as well

Check out this package of helpers for flow router. Things like pathFor aren’t built into flow router by default.

It might also be fun to built the helper yourself? :sunny:

just off the top of my head you could probably do something like this…

Template.registerHelper('routePath', name => name ? FlowRouter._routesMap[name] ? FlowRouter._routesMap[name].path : undefined : undefined)

Thank you @vigorwebsolutions, that didn’t seem to be the issue though. Should the file name also be the same as the template name perhaps?

Maybe I should just try ReactRouter

Yeah, that’s the package that I loaded. Can’t check if the pathFor works though since the landing page isn’t even loading

No, the file name can be whatever you want. You could have all of your templates in one file, if that was your prerogative.

Are you using the kadirahq:blaze-layout package?

You could certainly switch to another router, but I think the consensus is that FlowRouter is an easy, straightforward router to use.

Thanks guys, it’s miraculously working now. Must have needed a system reboot or something