2017-06-11 72 views
0

我試圖實現使用下面的代碼路由:聚合物路由 - 歷史管理

HTML : 

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

<iron-pages 
selected="[[page]]" 
attr-for-selected="name" 
fallback-selection="view404" 
role="main"> 
     <my-view1 page="{{page}}" name="view1"></my-view1> 
     <my-view2 page="{{page}}" name="view2"></my-view2> 
     <my-view404 page="{{page}}" name="view404"></my-view404> 
</iron-pages> 

和腳本是:

static get observers() { 
    return [ 
     '_routePageChanged(routeData.page)', 
    ]; 
    } 
_routePageChanged(page) { 
    // Polymer 2.0 will call with `undefined` on initialization. 
    // Ignore until we are properly called with a string. 
    /*if (page === undefined) { 
     return; 
    }*/ 

    // If no page was found in the route data, page will be an empty string. 
    // Deault to 'view1' in that case. 
    this.page = page || 'home'; 
    document.body.scrollTop = document.documentElement.scrollTop = 0; 
    // Close a non-persistent drawer when the page & route are changed. 
    /*if (!this.$.drawer.persistent) { 
     this.$.drawer.close(); 
    }*/ 
} 

_pageChanged(page) { 
    // Load page import on demand. Show 404 page if fails 
    var resolvedPageUrl = this.resolveUrl('my-' + page + '.html'); 
    Polymer.importHref(
     resolvedPageUrl, 
     null, 
     this._showPage404.bind(this), 
     true); 
} 

一切工作正常,但是當我嘗試第二次訪問查看(view2)然後使用瀏覽器後退按鈕。只有屏幕上的網址發生變化,但不是視圖。我看着它,發現_routePageChanged(page)方法沒有被調用。有任何想法嗎?

一個奇怪的觀察,我在運行Apache 2.4.23的遠程服務器上遇到問題,但在本地主機上運行的Apache 2.4.18或Nginx上沒有遇到問題。我不確定這些信息是否相關。

回答