0

我的 Polymer 2 应用程序一直有问题,我首先通过它是路由,但我发现在点击此页面后,当导航回页面时 Dom-if 触发它并没有重新触发。

例如,

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

使用我的导航选择器时也会发生这种情况,该选择器的设置类似于 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>
4

1 回答 1

0

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

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

所以 url 应该是 matparties/6719 以匹配模式并解析为 dom-if

于 2018-08-06T15:41:52.463 回答