krasimir / navigo

A simple vanilla JavaScript router.
MIT License
2.74k stars 249 forks source link

Feature request: Enable using `updatePageLinks` on arbitrary elements (not just `document`). #295

Open ejez opened 3 years ago

ejez commented 3 years ago

Thanks for the work on this library.

Just started exploring navigo, and found how data-navigo and updatePageLinks can greatly simplify adding internal app links. However they become useless when the app is using web components, because querying for the links is hardcoded to document.querySelectorAll which does not traverse the shadow dom.

I suggest adding an optional argument element (with document as default) to the functions findLinks and updatePageLinks. This argument will be the subject element where the links are searched for. (element.querySelectorAll instead of document.querySelectorAll.)

This simple change will allow for more flexible use of this functionality. Web components are increasingly being adopted.

Another option is to make use of https://github.com/Georgegriff/query-selector-shadow-dom to allow traversing all the shadow doms, even if they are deeply nested.

Thank you in advance.

alanalvarado commented 2 years ago

how do I use updatePageLinks?