API Docs for: 0.3.0
Show:

PageRouter.Page Class

Defined in: lib/mini-pages.js:487

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 PageRouter

    A PageRouter instance.

  • path String

    The path associated with the page.

  • [options] Object | String | Function optional

    Can either be an object of options, the name of a template, or a function that will act as the last before filter.

    • [to] String optional

      The name of a template to render.

    • [as] String optional

      The 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 optional

      The name of a template to use for a layout.

    • [nav] String optional

      A key to use for nav. Most useful in applying conditional classes to navigation bars.

    • [before] Function | Array optional

      A 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
)
chainable

Set the name of the page. Primarily used in path helpers.

Parameters:

  • name String

    The 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
)
chainable

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 | Array

    A function or array of callbacks.

layout

(
  • layout
)
chainable

Set the default layout for this page.

Parameters:

  • layout String

    The name of the template to use as a layout.

Example:

page.layout("layoutTemplateName");

nav

(
  • nav
)
chainable

Set the default nav key for this page.

Parameters:

  • nav String

    The name of the default nav key to use for this page.

Example:

page.nav("posts"); // sets the nav key primarily used for nav bars.

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 optional

    An 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
)
chainable

Set a default template name for the page.

Parameters:

  • template String

    The name of a template.