Static GitHub Issues

[2912] How to replace attributes in links?

prev: Rename issue tags?
next: vue.config seems to be inaccessible from within nuxt

Hi. I have small script in my default layout

mounted () {
    let links = document.querySelectorAll('a[href]:not([href^=mailto]):not([class^=addfollow])')
      console.log(links)
    for (let i = 0; i < links.length; i++) {
      if (links[i].hostname != window.location.hostname) {
        links[i].target = '_blank'
        links[i].rel = 'noopener nofollow noreferrer'
      }
    }
  }

This adds target="_blank" to all links on the page. It works fine, but when I hit 404 (I have 404 layout for that) and after returning back - scripts doesn't work, all links remains unchanged.

Is there's the way to fix this? Where shoould I put such scripts using Nuxt? Maybe placing it in default.vue layout is not good idea?

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c2528">#c2528</a>)</em></sub></div>