每次访问时重新加载页面
Reloading a page every time it gets accessed
是否可以在每次通过 app-route 元素访问页面时重新加载页面(如 /home 或 /photos)?
<app-location route="{{route}}" url-space-regex="^[[rootPath]]">
</app-location>
<app-route
route="{{route}}"
pattern="[[rootPath]]:page"
data="{{routeData}}"
tail="{{subroute}}"></app-route>
<iron-pages
selected="[[page]]"
attr-for-selected="name"
fallback-selection="view404"
role="main">
<my-home name="home"></my-home>
<my-discover name="discover"></my-discover>
<my-pages name="pages"></my-pages>
<my-view404 name="view404"></my-view404>
</iron-pages>
在我的例子中,我使用了 Polymer Starter Kit 并且我的网络应用程序包含多个页面,例如 /home 和 /discover,都可以通过左侧抽屉中的链接访问。
现在,即使我在应用程序中导航到另一个页面后,该应用程序似乎仍保留了页面或菜单的 'state',例如从 /home 导航到 /discover 保留了整个当我重新访问 /home 页面时 /home 页面的状态(滚动位置、打开的菜单等)。
我希望应用程序在每次访问页面时重新加载页面,以便它自动丢弃页面之前的状态。js 中的一些 onPageLoad 是否有可能,或者是否有其他选项应用程序路由元素可用吗?
谢谢!
Are there other options for the app-route element available?
不确定,但我认为不会。
顺便说一句,正如您在 source 中所见,该行为来自 iron-location
(包含在 app-location
中)。它只监听 body 元素上的点击事件,因此您可以在它进入 body 之前停止事件传播。
例如(未测试)
<dom-module>
...
<a href='/discover' on-click='stopPropagation'>
...
stopPropagation (event) {
event.stopPropagation()
}
...
</dom-module>
是否可以在每次通过 app-route 元素访问页面时重新加载页面(如 /home 或 /photos)?
<app-location route="{{route}}" url-space-regex="^[[rootPath]]">
</app-location>
<app-route
route="{{route}}"
pattern="[[rootPath]]:page"
data="{{routeData}}"
tail="{{subroute}}"></app-route>
<iron-pages
selected="[[page]]"
attr-for-selected="name"
fallback-selection="view404"
role="main">
<my-home name="home"></my-home>
<my-discover name="discover"></my-discover>
<my-pages name="pages"></my-pages>
<my-view404 name="view404"></my-view404>
</iron-pages>
在我的例子中,我使用了 Polymer Starter Kit 并且我的网络应用程序包含多个页面,例如 /home 和 /discover,都可以通过左侧抽屉中的链接访问。
现在,即使我在应用程序中导航到另一个页面后,该应用程序似乎仍保留了页面或菜单的 'state',例如从 /home 导航到 /discover 保留了整个当我重新访问 /home 页面时 /home 页面的状态(滚动位置、打开的菜单等)。
我希望应用程序在每次访问页面时重新加载页面,以便它自动丢弃页面之前的状态。js 中的一些 onPageLoad 是否有可能,或者是否有其他选项应用程序路由元素可用吗?
谢谢!
Are there other options for the app-route element available?
不确定,但我认为不会。
顺便说一句,正如您在 source 中所见,该行为来自 iron-location
(包含在 app-location
中)。它只监听 body 元素上的点击事件,因此您可以在它进入 body 之前停止事件传播。
例如(未测试)
<dom-module>
...
<a href='/discover' on-click='stopPropagation'>
...
stopPropagation (event) {
event.stopPropagation()
}
...
</dom-module>