简体   繁体   English

应用程序路由器“执行”未渲染:聚合物

[英]app-router “go” is not rendering : Polymer

I am trying to replace a component on the screen using app-router element but it doesn't render anything. 我正在尝试使用app-router元素替换屏幕上的组件,但它不呈现任何内容。 Below are the details. 以下是详细信息。

There are two major elements in " my-element.html ". my-element.html ”中有两个主要元素。 One is the side bar and other is the main panel. 一个是侧栏,另一个是主面板。 I want to replace the main panel with appropriate element based on the route. 我想根据路线将主面板替换为适当的元素。 However, it doesn't render any element but modifies the url. 但是,它不呈现任何元素,而是修改url。

Please help 请帮忙

my-element.html my-element.html

<dom-module id ="my-element">
<template> 

<paper-drawer-panel id="drawerpanel">

  <aq-sidebar></aq-sidebar>

  <app-router div="app-router" mode="hash">
    <app-route path="/editor" import="../layouts/editor.html"></app-route>
    <app-route path="/analyze" import="../layouts/analyze.html"></app-route>
    <app-route path="/community" import="../layouts/community.html"></app-route>
  </app-router> 

</paper-drawer-panel>
</template>
<script>
 Polymer({ is:'my-element',
           listeners: {'change-menu': 'menuChanged',},
           menuChanged(newMenu) { this.$$('app-router').go("/editor", {replace:true});}
        })
</script> </dom-module>

aq-sidebar.html aq-sidebar.html

<dom-module id='aq-sidebar'>
<template>
 <paper-header-panel class='sidenav fit'>
  <paper-toolbar>
    <div class="title">AimsQuant</div>
    <paper-icon-button icon="icons:menu" on-tap="toggleMenu"></paper-icon-button>
  </paper-toolbar>
  <paper-menu attrForSelected="data-panel" iron-select="onSelected">
    <paper-icon-item noink  data-panel="editor">
      <iron-icon item-icon icon="vaadin-icons:twin-col-select"></iron-icon>
      <span class="item-text">Editor</span>
      <!--a is="pushstate-anchor" href="#/editor"></a-->
    </paper-icon-item>

    <paper-icon-item data-panel="analyze">
      <iron-icon item-icon icon="vaadin-icons:chart"></iron-icon>
      <span class="item-text">Analyze</span>
    </paper-icon-item>

<script> Polymer({
    is: 'aq-sidebar',

    listeners: {
      'iron-select': 'onSelected',
    },

    onSelected() {
      this.fire('change-menu', {menu : this.menuSelected})
    },


  });
  </script>
</dom-module>

First, this import style is strange, I do think that it would be right if you use the iron-selector to switch between the view components that you've made, and import then using the importHref function, also you should use the Set function of polymer to change the path instead of this Go function. 首先,这种导入样式很奇怪,我认为如果您使用铁选择器在已制成的视图组件之间进行切换,然后使用importHref函数进行导入,那也是正确的,也应该使用Set函数聚合物以更改路径而不是此Go函数。 like this: 像这样:

<app-location route="{{ route }}"></app-location>
<app-route route="{{ route }}"
           pattern="/:page"
           data="{{ routeData }}"
           tail="{{ subroute }}"></app-route>

<iron-pages role="main"
            attr-for-selected="route"
            selected="[[ page ]]">
    <my-editor route="editor"></my-editor>
    <my-analyze route="analyze"></my-analyze>
    <my-community route="community"></my-community>
</iron-pages>

<script>
     Polymer({ 
         is:'my-element',
         properties: {
             page: {
                 type: String,
                 notify: true,
                 reflectToAttribute: true,
                 observer: "_pageChanged"
             }
         },

         observers: [
             "_routePageChanged(routeData.page)"
         ],

         _changeRoute: function(e) {
             this.importHref(
                this.resolveUrl("my-" + e.detail.requestRoute), null, null, true);
             this.set("route.path", e.detail.requestRoute);
         },

         _routePageChanged: function(page) {
             this.page = page || "list";
         },
     })
</script>

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

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