如果不重新点燃聚合物

时间:2018-08-06 10:27:59

标签: polymer dom-if

我在使用Polymer 2应用程序时遇到了问题,我首先通过它进行了路由,但是我发现在点击该页面后,当导航到该页面时Dom-if触发时,它并​​没有重新触发。

EG,

如果我在url / matters / 6719上,它将显示详细信息页面,但是如果我单击“后退”按钮并转到url / matter,则dom-if如果不再被点击,它仍然向我显示详细信息页面,< / p>

使用我的导航选择器时也会发生这种情况,该选择器的设置类似于PWA入门工具包。

<link rel="import" href="../bower_components/polymer/polymer-element.html">
<link rel="import" href="../bower_components/app-route/app-location.html">
<link rel="import" href="../bower_components/app-route/app-route.html">
<link rel="import" href="../bower_components/iron-pages/iron-pages.html">
<link rel="import" href="../bower_components/iron-selector/iron-selector.html">
<link rel="import" href="shared-styles.html">
<link rel="import" href="Matters/matter-list.html">
<link rel="import" href="MatParties/matparty-list.html">
<link rel="lazy-import" href="Matters/matter-detail.html">


<dom-module id="my-matters">


  <template>
    <style include="shared-styles">
      :host {
        display: block;

        padding: 10px;
      }
    </style>

    <app-route route="{{route}}" pattern="/:matter_id" data="{{routeData}}" tail="{{subroute}}">
      <app-route route="{{subroute}}" pattern="/matparties/:this_page" data="{{pageData}}"></app-route>
    </app-route>

    <div class="card">
        <template is="dom-if" if="[[_subidIsDefined(pageData.this_page)]]">
            <matparty-list linkedmatpartyid="[[pageData.this_page]]"></matparty-list>
          </template>
<template is="dom-if" if="[[!_subidIsDefined(pageData.this_page)]]">
      <template is="dom-if" if="[[!_idIsDefined(routeData.matter_id)]]">
        <matter-list></matter-list>
      </template>
      <template is="dom-if" if="[[_idIsDefined(routeData.matter_id)]]">
        <matter-detail linkedmatterid="[[routeData.matter_id]]"></matter-detail>
      </template>
</template>

  </template>

  <script>
    class Matters extends Polymer.Element {
      static get is() { return 'my-matters'; }


      _subidIsDefined(subid) {

        //There are probably ways to optimize this
        if (subid) {

          return true;
        }

        return false;
      }

      _idIsDefined(id) {

        //There are probably ways to optimize this
        if (id) {
          return true;
        }

        return false;
      }

    }
    window.customElements.define(Matters.is, Matters);
  </script>

</dom-module>

1 个答案:

答案 0 :(得分:0)

您检查过图案了吗?通常,该模式应遵循url模式。...在您的情况下为“ url / matters / 6719”

由于您已经在路由器上定义了pattern =“ / matparties /:this_page”,并且 matparties 在'url / matters / 6719'中是!='matters',可能会产生错误。我不知道您是否定义了一个基本URL,它也会在这方面产生一些问题。

因此,网址应为matparties / 6719以匹配模式并解析为dom-if