聚合物应用程序路由重定向

时间:2016-06-07 21:16:41

标签: polymer polymer-1.0

我在Polymer中使用<app-route>。一切正常,除了重定向。我读过https://www.polymer-project.org/1.0/toolbox/routing,解释似乎很清楚,但由于某种原因,它并没有按照我想要的方式工作。

在视图的某处,我有一个元素......

<script>
    Polymer({
        is: 'user-auth',
        responseHandler: function(event) {
            var token = event.detail.response.d.token;
            if (token != '') {
                localStorage.setItem('access_token', token);
                this.set('route.path', '/hello');
            }

        }
    });
</script>

问题是,它会重定向到/x/y/z/hello而不是/hello作为绝对网址。我怎样才能使重定向成为绝对的?

1 个答案:

答案 0 :(得分:-3)

没有<app-route>,很难分辨。

另一个(脏)选项是:

<style>
  #redirect {
    display: none;
  }
</style>

...

<a id="redirect" href="/hello"></a>

...

<script>
  ...
  // at the place where you want to redirect
  this.$.redirect.click();
  ...
</script>