PageRouter Class
The main mini-pages class. Manages creating pages, rendering and responding to url path changes. You can only create one PageRouter instance.
Constructor
PageRouter
-
[options]
Parameters:
-
[options]
Object optionalPageRouter options
-
[autoRender]
Boolean optionalSet
false
to render manually (i.e. when you use the {{renderPages}} Handlebars helper -
[autoStart]
Boolean optionalSet to
false
to manually decide when to listen for url change events. -
[defaults]
Object optionalDefault options that will be applied to all PageRouter.Page instances.
-
Item Index
Methods
_runWithInvocation
-
page
-
[context]
Creates a new PageRouter.PageInvocation and runs the page. Then set's the router's layout, template, nav and invocation object (the object you get when you call in your html.
Parameters:
-
page
PageRouter.PageThe page instance.
-
[context]
Object optionalAn optional context object.
autoRender
()
Automatically render the router to the document.body. By default the router will use autoRender(). If you instead want to render the router's pages in a particular part of the DOM you can call render() instead and attach the document fragment manually. For example, the Handlebars helper {{renderPages}} does this.
autoStart
()
chainable
Automatically start the router by adding a callback to Meteor.startup. The router is auto started by default.
go
-
path
-
[state]
Navigate to a given path.
Parameters:
-
path
StringThe path to navigate to.
-
[state]
Object optionalA state object to pass along.
Example:
var router = new Meteor.PageRouter({});
router.go("/posts/1234", { someState: "" });
invocation
-
[value]
Get or set the current invocation object. This is the object that is
available in your template html by using the page handlebars helper like
this: {{page.someProperty}}. The object gets its values from a before
filter calling this.set("key", "value")
. The value is stored in Session
so that it's reactive and survives hot code pushes.
Parameters:
-
[value]
Object optionalIf an object is passed it will be set, otherwise the current value will be returned.
Returns:
isRendered
()
Boolean
Returns true of the render() method has been called at least once. Does not mean that anything has been attached to the dom.
Returns:
isStarted
()
Boolean
Returns true of the start() method has been called
Returns:
layout
-
[value]
Reactively get or set the current layout.
Parameters:
-
[value]
String optionalThe name of the layout template.
Returns:
layoutEquals
-
value
Reactively test the current layout name for equality with the passed value.
Parameters:
-
value
StringThe name of the layout template to test quality.
Returns:
match
-
path
-
[options]
Create a new PageRouter.Page and return it.
Parameters:
-
path
StringThe path to match.
-
[options]
Object optionalOptions to pass to the PageRouter.Page constructor.
Returns:
Example:
// with options
var router = new Meteor.PageRouter({});
router.match("/posts/:_id", { to: "templateName" };
// no options
var router = new Meteor.PageRouter({});
router.match("/posts/:_id").to("templateName");
pages
-
pages
Create a bunch of pages at once.
Parameters:
-
pages
ObjectAn object of page definitions where the key is a url path and the values are options to the PageRouter.Page constructor.
Example:
var router = new Meteor.PageRouter({});
router.pages({
"/posts/:_id": {
to: "templateName",
layout: "layoutName",
nav: "nav key",
before: [ before callbacks ],
as: "path helpers name"
}
});
path
()
String
Returns the router's current url path.
Returns:
render
()
DocumentFragment | String
Creates two isolated regions. One for the layout and one for the template. Uses Spark's native reactivity to re-render the layout or template if the router's current layout or template changes.
Returns:
run
-
path
-
page
-
[context]
If the path is different from the current path, creates a new PageRouter.PageInvocation and runs the page with the new invocation.
Parameters:
-
path
StringThe url path.
-
page
PageRouter.PageA page instance.
-
[context]
Object optionalAn optional context object.
start
()
chainable
Start listening for pushState events from the browser and responding to url changes. Call this to manually start listening. If you call autoStart() this will automatically be called from within a Meteor.startup callback. You usually shouldn't need to call this method.
template
-
value
Reactively get or set the current template.
Parameters:
-
value
StringThe name of the template.
Returns:
templateEquals
-
value
Reactively test the current template name for equality with the passed value.
Parameters:
-
value
StringThe name of the template to test quality.