PageRouter.Page Class
Controller and container class for a page route. The constructor function registers the page with the underlying pushState handler. For now, we are using page-js to do this. You shouldn't create Page instances directly. Instead, let the PageRouter manage this for you.
Constructor
PageRouter.Page
-
router
-
path
-
[options]
Parameters:
-
router
PageRouterA PageRouter instance.
-
path
StringThe path associated with the page.
-
[options]
Object | String | Function optionalCan either be an object of options, the name of a template, or a function that will act as the last before filter.
-
[to]
String optionalThe name of a template to render.
-
[as]
String optionalThe name used in path helpers. All names will get a path helper like this:
Path. These path helpers are available as methods like Meteor.postShowPath() and as Handlebars helpers. -
[layout]
String optionalThe name of a template to use for a layout.
-
[nav]
String optionalA key to use for nav. Most useful in applying conditional classes to navigation bars.
-
[before]
Function | Array optionalA function or array of functions to be called before the layout and template are rendered.
-
Example:
new PageRouter.Page(router, "/posts/:_id", {
to: "templateName",
as: "pathHelper",
layout: "layoutTemplateName",
nav: "navKey",
before: [firstFilter, secondFilter]
});
Methods
_register
()
private
Registers the page with the underlying pushState handler. We're using page-js.
as
-
name
Set the name of the page. Primarily used in path helpers.
Parameters:
-
name
StringThe name of the page, and of the path helper prefix.
Example:
page.as("postShow");
// results in a path helper attached to Meteor and available
// in Handlebars.
// {{postShowPath}}
// Meteor.postShowPath({});
before
-
callbacks
A function or array of functions to call before rendering the page. The
before callbacks will be called with this
set to a
instance.
Parameters:
-
callbacks
Function | ArrayA function or array of callbacks.
layout
-
layout
Set the default layout for this page.
Parameters:
-
layout
StringThe name of the template to use as a layout.
Example:
page.layout("layoutTemplateName");
pathWithContext
-
[context]
Given a context object, returns a url path with the values of the context object mapped over the path. This method is attached to a Handlebars helper and to Meteor to call from JavaScript directly. For example, given a page named "postShow" you will get a Handlebars helper {{postShowPath}} and Meteor.postShowPath({});
Parameters:
-
[context]
Object optionalAn optional context object to use for interpolation.
Example:
// given a page with a path of "/posts/:_id/edit"
var path = page.pathWithContext({ _id: 123 });
// > /posts/123/edit
to
-
template
Set a default template name for the page.
Parameters:
-
template
StringThe name of a template.