每个路线的应用程序模板中的页面标题 - 正确的方法是什么? [英] Page Titles in Application template per-route - what's the right way to do this?

查看:66
本文介绍了每个路线的应用程序模板中的页面标题 - 正确的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我正在更改每个路线的页面标题。但是,页面标题不在我使用的主{{插口}}之外,即:

In my app, I'm changing the page title per route. However, the page title is outside the main {{outlet}} I'm using, i.e:

application.handlebars:

application.handlebars:

<h1>{{pageTitle}}</h1>

{{outlet}}

我想在小孩中设置pageTitle控制器,所以这是我正在做的:

I want to set pageTitle in the child controllers for each route, so this is what I'm doing:

App.WidgetsRoute = Ember.Route.extend
  setupController: (controller, model) ->
    @._super(controller, model)
    @controllerFor('application').set('pageTitle', 'Widgets')

这是正确的方法吗?我注意到一个类似的问题,但答案是没有' t说明如何做这个只是改变每个孩子的控制器,不一定是可计算的标题。

Is this the right way to do this? I noticed a similar question, but the answer there didn't explain how to do this for titles that only change per-child controller and aren't necessarily calculable.

推荐答案

你可以您的 ApplicationRoute 中的 setTitle 操作,可以设置 pageTitle ApplicationController

You can have a setTitle action in your ApplicationRoute, which could set the pageTitle in the ApplicationController:

// routes/application.js
actions: {
  setTitle: function(title) {
    this.get('controller').set('title', title);
  }
}

然后也许在 init 函数用于子路由或控制器。只需发送你想要的标题的动作,它应该冒泡到应用路由:

and then maybe in the init function for a child route or controller. just send the action with the title you want, it should bubble up to the application route:

  init: function() {
    this.send('setTitle', 'My Page Title');
    this._super();
  },

这篇关于每个路线的应用程序模板中的页面标题 - 正确的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆