小编nt.*_*bas的帖子

铁路由器不显示notFound页面

TL,DR:给定路由器仅在客户端运行的情况下,如何使未找到的模板在全局布局模板中工作(这是要求:客户端和服务器路由是分开的。)

我需要iron:router在无法与任何路由器匹配时显示默认模板。
在我的应用程序中,所有路由器都是客户端(router.js文件位于客户端文件夹中。)
到目前为止,这是我的代码:

  1. 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)

  1. ApplicationLayout.html

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

meteor iron-router

1
推荐指数
1
解决办法
2328
查看次数

标签 统计

iron-router ×1

meteor ×1