简体   繁体   English

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

[英]How to display current active page title in Aurelia.JS

I'm using aurelia JS now. 我现在正在使用aurelia JS。 And I have a problem when aurelia start routing, I want to change the title page into current location in my body tag, exactly I mean not the <title> tag but the inside body 当aurelia开始路由时,我有一个问题,我想将标题页更改为我的body标签中的当前位置,我的意思是不是<title>标签而是内部正文
I've a dig around and search for the tutorial but until now I don't get the right answer 我正在挖掘并搜索教程,但直到现在我还没有得到正确的答案

I attached my code 我附上了我的代码

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

I want my ${title} display a current active page. 我希望我的$ {title}显示当前活动页面。 I have search around but not found the answer 我有搜索但没有找到答案

Here my app.js code 这是我的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');
  }
}

You can use the currentInstruction.config.title of the router object: 您可以使用路由器对象的currentInstruction.config.title

this.router.currentInstruction.config.title;

Remember that you might have to bind the router to the web component. 请记住,您可能必须将路由器绑定到Web组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM