首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >应用程序路由器不以强制方式工作。

应用程序路由器不以强制方式工作。
EN

Stack Overflow用户
提问于 2015-02-24 15:01:15
回答 1查看 664关注 0票数 0

我有一个聚合物定制元素:

代码语言:javascript
复制
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../bower_components/core-animated-pages/core-animated-pages.html">
<link rel="import" href="../../../bower_components/app-router/app-router.html">

<polymer-element name="custom-pages" attributes="selected">
    <template>
        <link rel="stylesheet" href="custom-pages.css">

        <app-router id="router" bindRouter core-animated-pages transitions="cross-fade-all" trailingSlash="ignore">
            <template repeat="{{page in pages}}">
                <app-router path="{{page.path}}" import="{{page.url}}"></app-router>
            </template>
        </app-router>
    </template>
    <script>
        (function() {
            Polymer({
                selected: 0,
                pages: [{
                    path: "/home",
                    url: '../custom-home/custom-home.html'
                }, {
                    path: "/about",
                    url: '../custom-about/custom-about.html'
                }],
                selectedChanged: function(oldValue, newValue) {
                    router = this.$.router;
                    router.go(this.pages[newValue].path);
                }
            });
        })();
    </script>
</polymer-element>

元素自定义--主页和自定义--在“选择”更改时应该延迟加载,但不会发生(没有显示页面)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-25 10:55:13

您的template定义中有语法错误,嵌套标记是app-route而不是app-routeR

代码语言:javascript
复制
<app-router id="router" ...>
  <template repeat="{{page in pages}}">
    <!--      ⇓ superfluous r, nested are app-route -->
    <app-router path="{{page.path}}" import="{{page.url}}"></app-router>
    <!-- SHOULD BE: -->
    <app-route path="{{page.path}}" import="{{page.url}}"></app-route>
  </template>
</app-router>

目前,您已经创建了一捆空路由器。

另外,文件上说

如果您使用go(path, options),您还应该在路由器上将模式设置为hashpushstate

我不确定这是否影响到您的情况,因为您似乎没有通过options

希望能帮上忙。

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

https://stackoverflow.com/questions/28699130

复制
相关文章

相似问题

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