Search code examples
javascripttypescriptroutesaurelia

How do I keep on the same page by clicking on internal anchor links, using Aurelia?


I am working on a styleguide for a project and currently I would like to have a basic clicking behaviour on anchor links, so that they scroll to the correspondent id.

As an example:

<a href="#section"></a>

That scrolls down to:

<div id="section"></div>

In Aurelia, the default behaviour is to treat links as routes. I can't get the internal link to work, as it immediately sends me to an external page.

Does someone know how to overcome this issue? Thanks!


Solution

  • You can disable the Aurelia router highjacking the link in several different ways, as per the documentation. One of the ways is to use one of these special attributes:

    <a href="/some/link" download>Skip Hijacking</a>
    <a href="/some/link" download="">Skip Hijacking</a>
    <a href="/some/link" router-ignore>Skip Hijacking</a>
    <a href="/some/link" router-ignore="">Skip Hijacking</a>
    <a href="/some/link" data-router-ignore>Skip Hijacking</a>
    <a href="/some/link" data-router-ignore="">Skip Hijacking</a>