如何从子元素更改应用程序路径位置

时间:2017-08-02 00:13:06

标签: polymer web-component custom-element

我创建了基于app-route的项目。某些事件我需要将路由更改为不同的根。

的index.html

<< >>

MY-app.html

    

<my-app></my-app>

着陆-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>

1 个答案:

答案 0 :(得分:2)

添加:      在landing-app.html

中的<app-location route="{{route}}"></app-location>之后<template>
<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