TL,DR:给定路由器仅在客户端运行的情况下,如何使未找到的模板在全局布局模板中工作(这是要求:客户端和服务器路由是分开的。)
我需要iron:router在无法与任何路由器匹配时显示默认模板。
在我的应用程序中,所有路由器都是客户端(router.js文件位于客户端文件夹中。)
到目前为止,这是我的代码:
Router.configure({
layoutTemplate: 'ApplicationLayout'
});
Router.map(function() {
this.route('home', {
path: '/',
onAfterAction: function() {
document.title = 'MyApp';
},
action: function() {
this.render('Home');
this.render('Menu', {to: 'menu'});
this.render('Footer', {to: 'footer'});
}
});
this.route('notFound', {
path: '*',
onAfterAction: function() {
document.title = 'Page not found - MyApp';
},
action: function() {
this.render('NotFound');
this.render('Menu', {to: 'menu'});
this.render('Footer', {to: 'footer'});
}
});
});Run Code Online (Sandbox Code Playgroud)
<template name="ApplicationLayout">
<div class="nav-container">
{{> yield "menu"}}
</div>
<div class="main-container">
{{> yield}}
</div>
<div class="footer-container">
{{> …Run Code Online (Sandbox Code Playgroud)