Navigating within the PWA
When we load the AMP content, there's another task we need to do to ensure a good user experience. If the user clicks a link to an AMP page within the AMP content, the AMP page will be loaded directly, and they will navigate away from the PWA context. However, the desired behavior is that the AMP page should be loaded into the PWA shell to replace the current content.
To achieve this, we can add a click handler that will prevent the default browser action that navigates to the linked page, and instead, we'll call the showAMPContent function again to repeat the process of fetching the AMP document and passing it to the Shadow AMP runtime to render.
To achieve, this we need to target the links within the AMP content ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access