标签: iron-pages

如何使用app-route在聚合物3中实现路由

我一直坚持在聚合物3中实施路由。我遵循了app-route文档中提供的基本指南。但是在加载网页时,我看不到任何组件被加载。我签入shadow DOM,没有看到任何DOM呈现。不知道我在想什么。这是代码。

static get properties() {
      return {
      page:{
        type: String,
        reflectToAttribute: true,
        observer: '_pageChanged'
      }
      };
    }
    _pageChanged(currentPage, oldPage){
    	  console.log('CURRENT - ', currentPage);
    	  console.log('OLD - ', oldPage);
    	  switch(currentPage){
    		  case 'home':
    			import('./home-comp.js').then()
    			break;
    		case 'about':
    			import('./about-comp.js').then()
    			break;
    		case 'contact':
    			import('./contact-comp.js').then()
    			break;
    		default:
    			this.page = 'home';
    	  }
      }
Run Code Online (Sandbox Code Playgroud)
<app-route
          route="{{route}}"
          pattern="/:page"
          data="{{routeData}}"
          tail="{{subroute}}">
</app-route>

<home-comp name="home"></home-comp>
<about-comp name="about"></about-comp>
<contact-comp name="contact"></contact-comp>
Run Code Online (Sandbox Code Playgroud)

我看不到有关Polymer 3的大量文档可用于检查问题。在查看Polymer的默认示例Web应用程序shop。之后,我遇到了一些适当的解决方案。我想与社区分享给任何需要帮助的人。

app-route iron-pages polymer-3.x

2
推荐指数
1
解决办法
661
查看次数

标签 统计

app-route ×1

iron-pages ×1

polymer-3.x ×1