我在网络应用程序内部路由时遇到问题,问题是我的index.html中有不同的部分,并且在这些部分之一上我有一个纸质按钮元素,所以我想路由到当用户点击此按钮时的其他部分,这里有一些代码,以便您可以更好地理解:
索引.html
<iron-pages attr-for-selected="data-route" selected="{{route}}" id="main_pages">
<section data-route="home">
<my-register></my-register>
<div class="div-vertical-flex">
<my-generalcard id="generalcard_1"></my-generalcard>
<my-generalcard id="generalcard_2"></my-generalcard>
<my-generalcard id="generalcard_3"></my-generalcard>
</div>
</section>
<section data-route="blog">
<my-blog></my-blog>
</section>
<section data-route="pricing">
<my-pricing-start></my-pricing-start>
<my-pricingaccount></my-pricingaccount>
</section>
<section data-route="contactus">
<my-contact></my-contact>
</section>
<section data-route="product">
<my-product></my-product>
</section>
<section data-route="login">
<my-login></my-login>
</section>
<section data-route="register">
<my-registerpage></my-registerpage>
</section>
</iron-pages>
包含带有按钮的元素的部分是:home
,元素是:my-register
。
路由.html
page('/register/:email', function(data) {
app.route = 'register';
app.params = data.params;
});
上面是routing.html中的函数。我在其中声明我将接收网址/register/:email
,并且我将重定向到注册部分。
my-register.html
<paper-button raised id="bt_register" on-tap="handleRegisterTap" class="paper-button-fullsize">
Continue...
<iron-icon icon="arrow-forward" suffix></iron-icon>
</paper-button>
<span>Have an account already? Please <a href="{{baseUrl}}login">Login</a></span>
</paper-material>
</template>
<script>
Polymer({
is: 'my-registerform',
properties: {
email: {
type: String,
notify: true
}
},
handleRegisterTap: function(){
//this.$$('#main_pages').select("register/" + this.email);
}
});
function clearInput () {
document.querySelector('#email').value="";
}
</script>
问题是我想重定向到该部分,但找不到方法,我尝试过: this.$$('#main_pages').select("register/"+ this.email);
但我“找不到”。
我很感激任何帮助。
最佳答案
我有一个解决方案:
handleRegisterTap: function(){
app.params = this.email;
app.route = 'register';
}
通过这种方式,我自动重定向到其他部分。
关于javascript - 使用纸质按钮点击事件进行路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36121858/