如何在Aurelia.JS中显示当前活动页面标题

时间:2016-01-03 13:52:29

标签: javascript aurelia aurelia-navigation

我现在正在使用aurelia JS。当aurelia开始路由时,我有一个问题,我想将标题页更改为我的body标签中的当前位置,我的意思是不是<title>标签而是内部正文 我在挖掘并搜索教程,但直到现在我还没有得到正确的答案

我附上了我的代码

<template bindable="router">
  <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header" mdl="layout">
    <header class="mdl-layout__header mdl-color--primary">
      <div class="mdl-layout__header-row">
        <!-- Title -->
        <span class="mdl-layout-title">${title}</span>
        <!-- Add spacer, to align navigation to the right -->
        <div class="mdl-layout-spacer"></div>
        <button class="android-more-button mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect"
                id="more-button">
          <i class="material-icons">more_vert</i>
        </button>
        <ul class="mdl-menu mdl-js-menu mdl-menu--bottom-right mdl-js-ripple-effect" for="more-button" mdl="menu">
          <li class="mdl-menu__item">5.0 Lollipop</li>
          <li class="mdl-menu__item">4.4 KitKat</li>
          <li disabled class="mdl-menu__item">4.3 Jelly Bean</li>
          <li class="mdl-menu__item">Android History</li>
        </ul>
        <!-- Navigation. We hide it in small screens. -->
      </div>
    </header>

我希望我的$ {title}显示当前活动页面。我有搜索但没有找到答案

这是我的app.js代码

import $ from 'jquery';
import {AuthorizeStep} from 'resources/AuthorizeStep';

export class App {
  configureRouter(config, router) {
    config.title = 'Aurelia';

    config.map([
      {route: ['penyakit',''], name: 'penyakit', moduleId: 'pages/penyakit/penyakit', nav: true, title: 'Beranda',settings:{icon:'dashboard',color:'teal'}},
      {route: 'penyakit', name: 'penyakit', moduleId: 'pages/penyakit/penyakit', nav: true,auth:true, title: 'Penyakit',settings:{icon:'inbox',color:'blue'}},
      {route : ['penyakit/tambah','penyakit/edit/:id'], name : 'tambah_penyakit' , moduleId : 'pages/penyakit/tambah_penyakit',nav:false,auth: true,title:'Tambah Penyakit'},
      {route: 'gejala', name: 'gejala', moduleId: 'pages/gejala/gejala', nav: true, title: 'Gejala',settings:{icon:'event notes',color:'orange'}},
      {route: 'users', name: 'users', moduleId: 'pages/user/users', nav: true, title: 'Aturan CF',settings:{icon:'layers',color:'green'}},
      {route: 'users', name: 'users', moduleId: 'pages/user/users', nav: true, title: 'divider',settings:{icon:'description'}},
      {route: 'users', name: 'users', moduleId: 'pages/user/users', nav: true, title: 'Pengaturan',settings:{icon:'settings',color:'grey'}},
    ]);
    config.addPipelineStep('authorize', AuthorizeStep);

    this.router = router;
  }

  change_app_bar_color(color)
  {
    var app_bar = $('#app_bar');
    app_bar.removeClass('blue-inbox teal orange green grey');
    app_bar.addClass(color);
    console.log('F');
  }
}

1 个答案:

答案 0 :(得分:5)

您可以使用路由器对象的currentInstruction.config.title

this.router.currentInstruction.config.title;

请记住,您可能必须将路由器绑定到Web组件。