Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
  <body>
    <nav id="outside-router">
      <button data-link="route-1">Route-1</button>
      <button data-link="route-2">Route-2</button>
    </nav>
    <div id="router-wrapper" role="group" tabindex="-1">
    </div>
    
    <div id="route-1">
      <main>
        <h1>
          Route-1
        </h1>
        <p>Doggo ipsum i am bekom fat boofers big ol pupper pupperino long bois wow such tempt, dat tungg tho you are doing me the shock dat tungg tho you are doin me a concern. Sub woofer borkf long bois boofers h*ck aqua doggo, fat boi wow very biscit pupper. Smol maximum borkdrive big ol pupper waggy wags, length boy wow such tempt. Porgo you are doing me the shock long water shoob blep shibe, yapper heckin good boys doggo, boofers noodle horse shooberino. Dat tungg tho ur givin me a spook wow such tempt doggo, borking doggo ruff much ruin diet h*ck, corgo big ol pupper. You are doing me a frighten doge long bois big ol puggo dat tungg tho, much ruin diet shooberino bork heckin angery woofer. I am bekom fat long bois very taste wow woofer shooberino, woofer thicc. Borking doggo big ol the neighborhood pupper super chub smol borking doggo with a long snoot for pats long water shoob, stop it fren I am bekom fat h*ck. Very hand that feed shibe super chub blep, you are doing me a frighten.</p>
      </main>
    </div>
    <div id="route-2">
      <h1>
        Route-2 (not in main landmark)         </h1>
      Before landmark
      <main>In landmark</main>
      After landmark
    </div>
   
  </body>
              
            
!

CSS

              
                #router-wrapper {
  background: beige;
  padding: 1em 1.5em;
}

#outside-router {
  background: cadetblue;
  padding: 1em;
}

.routeSkipHeading {
    position: relative;
}
.routeSkipLink {
    display: inline-block;
    margin-left: -0.75em;
    opacity: 0;
    position: absolute;
    text-decoration: none;
}
.routeSkipLink:before {
    content: '⇽';
    display: block;
}
.routeSkipLink:focus,
.routeSkipLink:hover {
    opacity: 1;
}
              
            
!

JS

              
                const routerWrapper = document.querySelector(`#router-wrapper`)

const routeSkipLink = () => {
  const targetID = 'outside-router'
  let a = document.createElement('a')
  a.setAttribute('id', 'skip-main')
  a.setAttribute('href', `#${targetID}`)
  a.classList.add('routeSkipLink')
  a.setAttribute('aria-label', `back to ${targetID}`)
  return a
}
const routes = {}

let cleanupFns = []

const initRoute = id => {
  const routeElement = document.querySelector(`#${id}`)
  const routeHeading = routeElement.querySelector('h1')
  routeHeading.classList.add('routeSkipHeading')
  routeHeading.prepend(routeSkipLink())
  routes[id] = routeElement
  routeElement.remove()
}

const setRoute = (id, clicked = false) => {
  cleanupFns.forEach(fn => fn())
  cleanupFns = []
  
  while (routerWrapper.firstChild) {
    routerWrapper.removeChild(routerWrapper.firstChild)
  }
 
  /* Here's part we can experiment with */
  routerWrapper.appendChild(routes[id])
  requestAnimationFrame(() => {
    // routerWrapper.focus()
    console.log('clicked',clicked)
    if (clicked && routes[id].querySelector('.routeSkipLink')) {
      routes[id].querySelector('.routeSkipLink').focus()
    }
  })
  /* End of part to experiment with */
}

initRoute(`route-1`)
initRoute(`route-2`)

setRoute(`route-1`)


document.querySelectorAll(`#outside-router [data-link]`).forEach(link => {
    const clickHandler = () => {
      setRoute(link.getAttribute('data-link'), true)
    }
    link.addEventListener('click', clickHandler)
  })
              
            
!
999px

Console