API Docs for: 0.3.0
Show:

PageRouter.PageInvocation Class

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

Created each time the url path changes and a page is run. The PageInvocation allows before filters to dynamically set the template, layout and nav, and provides methods for redirecting, stopping execution of the before filters and getting and setting page variables that will be cleaned up when a new page is run.

Instances are created automatically by the PageRouter when a path change causes the router's run method to be called. The PageInvocation instance is the value of this in all before filters.

Constructor

PageRouter.PageInvocation

(
  • router
  • page
  • [context]
)

Parameters:

  • router PageRouter

    A page router instance.

  • page PageRouter.Page

    A page instance.

  • [context] Object optional

    An optional context object.

Methods

done

()

Don't run any additional before filters.

Example:

// inside a before filter
function filter () {
  if (Meteor.loggingIn()) {
    this.template("loggingIn");
    this.done();
  }
}

get

(
  • key
)
Any

Gets a current invocation value.

Parameters:

  • key String

    The key.

Returns:

Any: The value associated with the key.

Example:

// inside before filter
function filter () {
  var post = this.get("post");
}

isDone

() Boolean

Returns true if the invocation has been marked as done.

Returns:

Boolean: True if the done() method has been called.

isStopped

() Boolean

Returns true if the invocation has been stopped.

Returns:

Boolean: True if the stop() method has been called.

layout

(
  • [value]
)
String

Gets or sets the invocation's layout template name.

Parameters:

  • [value] String optional

    An optional layout template name.

Returns:

String: If no value provided, returns the invocation's layout template name.

redirect

(
  • path
  • [state]
)

Stops the current page and redirects to a new path.

Parameters:

  • path String

    The path to redirect to.

  • [state] Object optional

    An optional state object to pass along.

Example:

// before filter
function filter () {
  this.redirect(Meteor.postIndexPath());
}

set

(
  • key
  • value
)

Set a page variable that can be accessed for the current invocation from handlebars or downstream before filters. These will be cleared when a new page is run (i.e. the url path changes). These values are accessible using the page Handlebars helper.

Parameters:

  • key String

    The key. Example: "post".

  • value Any

    Any value.

Example:

// inside before filter
function filter () {
  this.set("post", { _id: 1234 });
}

stop

()

Stops the current page run. Also stops pushState from being called. Call this to completely stop. No rendering, no more filters.

template

(
  • [value]
)
String

Gets or sets the invocation's template name.

Parameters:

  • [value] String optional

    An optional template name.

Returns:

String: If no value provided, returns the invocation's template name.

template

(
  • [value]
)
String

Gets or sets the invocation's nav key.

Parameters:

  • [value] String optional

    An optional nav key.

Returns:

String: If no value provided, returns the invocation's nav key.

toObject

() Object

Returns the invocation's dictionary. This is what is put into Session before the page is rendered.

Returns:

Object: The invocation's dictionary.

Attributes

context

Object

The context object from the page-js event.

page

PageRouter.Page

The invocation's PageRouter.Page instance.

params

Object

The params from the url path.