ostrio:iron-router-title

v1.0.3Published 9 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Reactive page title for Meteor and Iron-Router

Change document.title (page title) on the fly via iron-router's configuration.

This package supports title option defined in list below, ordered by prioritization:

  1. Router.route() [overrides all below]
  2. RouteController.extend()
  3. Router.configure()
  4. <title>My Title</title> [might be overridden by any above]

Install:

meteor add ostrio:iron-router-title

Demo Application:

Usage:

Set default title in your template, this title will be used if title isn't specified in router's configuration:

1<head>
2  <title>My default title</title>
3</head>

Set title property in router's or controller's configuration:

1// Set default document.title value in 
2// case router has no title property
3Router.configure({
4  title: 'Default title'
5});
6
7Router.route('account', {
8  template: 'account',
9  path: '/me/account',
10  title: 'My Account'
11});
12
13var LocationController = RouteController.extend({
14  title: "Location Title"
15});
16
17Router.route('locations', {
18  controller: LocationController
19});

Use function context:

1Router.route('account', {
2  template: 'account',
3  path: '/me/account/:_id',
4  title: function() {
5    return "Account of " + (this.data().getFullName());
6  },
7  data: function() {
8    var self = this;
9    return {
10      getFullName: function() {
11        return Meteor.users.findOne(self.params._id).fullName;
12      }
13    };
14  }
15});

To change title reactively, just pass it as function:

1Router.route('account', {
2  template: 'account',
3  path: '/me/account',
4  title: function() {
5    return i18n.get('account.document.title');
6  }
7});

In this example we've used ostrio:i18n package