首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从子元素更改app路由位置

如何从子元素更改app路由位置
EN

Stack Overflow用户
提问于 2017-08-02 08:13:06
回答 1查看 663关注 0票数 2

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

index.html

代码语言:javascript
复制
<my-app></my-app>

my-app.html

代码语言:javascript
复制
<!-- 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>

landing-app.html

当处理程序调用时,我需要更改到仪表板的路由。如何做到这一点?

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-02 09:42:49

在landing-app.html中的<template>之后添加:<app-location route="{{route}}"></app-location>

代码语言:javascript
复制
<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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45449503

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档