Skip to content

Commit

Permalink
add support for custom noRoutesTemplate and clarify default template #…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbutler committed Jan 14, 2017
1 parent 2125821 commit bdb6584
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,11 @@ method.
Router.configure({
layoutTemplate: 'ApplicationLayout',

template: 'DefaultTemplate'
template: 'DefaultTemplate',

// .
// .
// .
notFoundTemplate: 'RouteNotFound',

noRoutesTemplate: 'ReplacesSplashScreen'
});
```
Expand Down
20 changes: 12 additions & 8 deletions lib/router_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Router.prototype.createView = function () {
Router.prototype.lookupNotFoundTemplate = function () {
if (this.options.notFoundTemplate)
return this.options.notFoundTemplate;

return (this.routes.length === 0) ? NO_ROUTES_TEMPLATE : DEFAULT_NOT_FOUND_TEMPLATE;
};

Expand Down Expand Up @@ -102,8 +102,8 @@ Router.prototype.dispatch = function (url, context, done) {
if (!controller.isHandled()) {
// if we aren't at the initial state, we haven't yet given the server
// a true chance to handle this URL. We'll try.
// if the server CAN'T handle the router, we'll be back,
// but as the very first route handled on the client,
// if the server CAN'T handle the router, we'll be back,
// but as the very first route handled on the client,
// and so initial will be true.
var state = Deps.nonreactive(function () { return controller.location.get().options.historyState; });

Expand All @@ -115,19 +115,23 @@ Router.prototype.dispatch = function (url, context, done) {
// NOTE: this => controller
this.layout(this.lookupOption('layoutTemplate'), {data: {url: this.url}});

var notFoundTemplate = this.lookupOption('notFoundTemplate');
var errorTemplate;

if (self.routes.length === 0) {
errorTemplate = this.lookupOption('noRoutesTemplate') || NO_ROUTES_TEMPLATE;
} else {
errorTemplate = this.lookupOption('notFoundTemplate') || DEFAULT_NOT_FOUND_TEMPLATE;
}

if (!notFoundTemplate)
notFoundTemplate = (self.routes.length === 0) ? NO_ROUTES_TEMPLATE : DEFAULT_NOT_FOUND_TEMPLATE;
this.render(notFoundTemplate, {data: {url: this.url}});
this.render(errorTemplate, {data: {url: this.url}});
this.renderRegions();

// kind of janky but will work for now. this makes sure
// that any downstream functions see that this route has been
// handled so we don't get into an infinite loop with the
// server.
controller.isHandled = function () { return true; };
}
}

return done && done.call(controller);
}
Expand Down
12 changes: 7 additions & 5 deletions lib/templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,29 @@
<h1 style='text-align: center; margin: 0; font-size: 48pt;'>
iron:router
</h1>
<p style='text-align: center; font-size: 1.3em;'>
Organize your Meteor application.
<p style='text-align: center; font-size: 1.3em; color: red;'>
No route definitions found.
</p>
<div style='margin: 50px 0px;'>
<p>To create a route:</p>
<pre style='background: #f2f2f2; margin: 0; padding: 10px;'>
Router.route('/', function () {
this.render('Home', {
data: function () { return Items.findOne({_id: this.params._id}); }
});
});
</pre>
<p style="text-align:center"><small>To hide this page, set 'noRoutesTemplate' in <a href="http://iron-meteor.github.io/iron-router/#global-default-options" target="_blank">Router.configure()</a></small></p>
</div>
<div style='margin: 50px 0px;'>
<div style='margin: 50px 0px; text-align: center;'>
Check it out on Github:<br>
<a href='https://github.com/eventedmind/iron-router' target='_blank'>https://github.com/eventedmind/iron-router</a>
<a href='https://github.com/iron-meteor/iron-router/' target='_blank'>https://github.com/iron-meteor/iron-router/</a>
<br>
<br>
And check out the new Guide:<br>
<a href='https://iron-meteor.github.io/iron-router' target='_blank'>
https://iron-meteor.github.io/iron-router
</a>
</div>
</div>
</div>
</template>
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package.describe({
name: 'iron:router',
summary: 'Routing specifically designed for Meteor',
version: '1.0.12',
version: '1.1.0',
git: 'https://github.com/iron-meteor/iron-router'
});

Expand Down

0 comments on commit bdb6584

Please sign in to comment.