使用带聚合物的app-router

时间:2014-12-13 20:44:40

标签: polymer web-component

我正在尝试按照以下指南将app-router合并到我的Polymer应用程序中:

https://erikringsmuth.github.io/app-router/#/

https://erikringsmuth.github.io/app-router/#/databinding/1347queryParam1=Routing%20with%20Web%20Components

对于我已合并app-router的元素,我的Polymer代码如下:

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../app-router/app-router.html">

<polymer-element name="my-element">
  <template>

    <style></style>

    <app-router mode="pushstate">
      <app-route path="/:id" import="elements/new-page.html"></app-route>
    </app-router>

  </template>

  <script>
    Polymer({});
  </script>
</polymer-element>

id变量应绑定到下面的元素。 id只是用作获取特定JSON数据的索引。

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="my-service.html">

<polymer-element name="new-page" attribute="id">
  <template>

    <style></style>

    <my-service data="{{data}}"></my-service>

    <img src="{{data[id].bannerImage}}"/>
    <h2>{{data[id].contentHeading}}</h2>
    <template repeat="{{content in data[id].content}}">
      <img src="{{content}}" class="content"/><br>
    </template>

  </template>

  <script>
    Polymer({});
  </script>
</polymer-element>

但是当我导航到localhost:8000/1时,我收到404错误。我认为我没有正确使用app-router,因此错误。

有人能够发现我的错误吗?

2 个答案:

答案 0 :(得分:3)

我认为您必须在服务器上设置重写规则,因此它始终以index.html文件为目标。你几乎可以在任何地方找到这种路由,但是如果你需要一个Apache2,你可以从Zend Skeleton应用程序中选择一个:Zend Skeleton Application .htaccess file

不要忘记适应您的项目(尤其是index.html而不是index.php)。

答案 1 :(得分:1)

您将属性属性名称拼错为属性,这就是为什么它没有传递给您的元素...