我创建了基于应用程序路由的项目。某些事件我需要将路由更改为不同的根。
索引.html
<my-app></my-app>
我的应用.html
<!-- this app-route manages the top-level routes -->
<app-route
route="{{route}}"
pattern="/:view"
data="{{routeData}}"
tail="{{subroute}}"></app-route>
<!-- iron-pages selects the view based on the active route -->
<iron-pages selected="[[routeData.view]]" attr-for-selected="name">
<landing-app name="home" route="{{subroute}}"></landing-app>
<dashboard-app name="dashboard" route="{{subroute}}"></dashboard-app>
</iron-pages>
登陆应用程序.html
调用处理程序时,我需要更改到仪表板的路由。怎么办呢?
<dom-module id="landing-app">
<template>
<button on-click="_handlerCall">Change to Dashboard</button>
</template>
<script>
class LandingApp extends Polymer.Element {
static get is() {return 'landing-app'}
_handlerCall() {
this.set('route.path', '/dashboard') // but no luck :(
}
}
customElements.define(LandingApp.is, LandingApp);
</script>
</dom-module>
添加:<app-location route="{{route}}"></app-location>
在着陆应用程序中<template>
后.html
<dom-module id="landing-app">
<template>
<app-location route="{{route}}"></app-location>
<button on-click="_handlerCall"> Change to Dashboard</button>
</template>
<script>
class LandingApp extends Polymer.Element {
static get is() {return 'landing-app'}
_handlerCall() {
this.set('route.path', '/dashboard') // :)
}
}
customElements.define(LandingApp.is, LandingApp);
</script>
</dom-module>
app-location
文档: https://www.webcomponents.org/element/PolymerElements/app-route/elements/app-location