An extension of kadira:flow-router
to work with fourquet:actions
meteor add fourquet:routes
Routes extends kadira:flow-router
and compliments fourquet:actions
(Actions). In order to use Routes, Reflux needs to be included in the app with a package such as fourquet:reflux-core
, fourquet:reflux
or from NPM.
Routes can listen to action and perform actions. First, define actions:
Actions.SomeActions = Actions.create([
'anAction',
'anotherAction'
]);
Then listen:
Routes.listenTo(Actions.SomeActions.anAction, () => {
// do something, such as render a page
});
When an action is called, Routes will call its function.
Actions.SomeActions.anAction();
See the repository for full working example.
<template name="layout">
<h1>Welcome to the Routes Example!</h1>
<div><a href="/">Home</a></div>
<div><a href="/anotherPage">Another Page</a></div>
{{> Template.dynamic template=main}}
</template>
<template name="home">
This is home!
</template>
<template name="anotherPage">
This is anotherPage!
</template>
Actions.Main = Actions.createActions([
'goToHome',
'goToAnotherPage',
]);
Routes.route('/', {
name: 'home',
action() {
Actions.Main.goToHome();
},
});
Routes.route('/anotherPage', {
name: 'anotherPage',
action() {
Actions.Main.goToAnotherPage();
},
});
if (Meteor.isClient) {
Routes.listenTo(Actions.Main.goToHome, () => {
BlazeLayout.render('layout', {
main: 'home'
});
});
Routes.listenTo(Actions.Main.goToAnotherPage, () => {
BlazeLayout.render('layout', {
main: 'anotherPage'
});
});
}
More tests
0.0.2
MIT