Ad

Routing With Paper-button On-tap Event

- 1 answer

I'm having an issue with routing inside my web app, the problem is that I have a different sections in my index.html and on one of those sections I have a paper-button element so I would like to routing to other section when the user tap on this button, here is some code so you could understand better:

Index.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>

The section that contain the element with the button is: home and the element is: my-register.

routing.html

page('/register/:email', function(data) {
  app.route = 'register';
  app.params = data.params;
});

Above is the function in the routing.html.Where I declared that I'm going to received the url /register/:email and I will redirect to the register section.

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 target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" 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>

The problem is that I want to redirect to the section but I can't find a way to do it, I tried: this.$$('#main_pages').select("register/" + this.email);but I got "not found". I appreciate any help on that.

Ad

Answer

I got a solution for this:

handleRegisterTap: function(){
            app.params = this.email;
            app.route = 'register';
        }

In that way automatically i got a redirect to the other section.

Ad
source: stackoverflow.com
Ad