Coder Social home page Coder Social logo

next-isomorphic-link's Introduction

CircleCI

next-isomorphic-link

A tiny Next.js <Link/> wrapper that improves server-side rendered output with better keyboard navigation support

Usage

yarn add next-isomorphic-link

Replace import from of next/link with next-isomorphic-link:

- import Link from 'next/link'
+ import Link from 'next-isomorphic-link'

Why

The default <Link/> component usage looks like this (as of Next 9):

<Link href='/puppies'>
  <a>Puppies</a>
</Link>

When you view the source, or disable JavaScript, the markup will look like this:

<a>Puppies</a>

There are a few issues here:

  • <a> tags without href attributes are not tabbable (you can’t tab around the page)
  • When the page has’nt been rendered client side (e.g. JS disabled, slow network speed) the link will not be clickable
  • Once the bundle has been executed and the page is interactive, hitting Enter (or the spacebar if you have that option enabled) when focussed on the link will have no effect.

These are easy to fix:

  • Add the href attribute to the child <a> in the server-rendered markup (and remove it when mounted)
  • Add a tabIndex of 0 to the client-side rendered link to ensure tabbability (if that is a word)
  • Add an event handler for the Enter key

Changelog

  • 0.2.5: Added TypeScript declaration file
  • 0.2.3: Bump peer dependency version

next-isomorphic-link's People

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.