2

What is the correct way to implement internal linking in Polymer 2.0 (linking within the same page)? I cannot seem to get access to my components that are buried within ShadowDoms, so the traditional way of using <a href="#my_section">link to top</a> and <a name="my_section"></a> and <a id="my_section"></a> does not work.

I have also tried the solutions here to no avail:

The following code that I've tried all return null, even when I add an id to my component:

document.querySelector('#my_section'); //null
this.$.my_section; //null
this.root.querySelector('#my_section'); //null
this.shadowRoot.querySelector('#my_section'); //null 

Perhaps there is a way to accomplish this using <app-route>?

I'm quite new to Polymer so any advice would be appreciated. Thanks in advance.

VIN
  • 6,385
  • 7
  • 38
  • 77

1 Answers1

0

Please share more detailed code that which elements you want to access and manuplate. Here at this document

https://www.polymer-project.org/2.0/docs/devguide/dom-template

under the Static node map head shows shortly :

The this.$ hash is created when the shadow DOM is initialized. In the ready callback, you must call super.ready() before accessing this.$.

Cappittall
  • 3,300
  • 3
  • 15
  • 23