Ivan Revzin

Router Options for a Single Page App

Popular options:

Less Popular:

How to choose?

Criteria:

Router features

React Router

TanStack/router

Reach Router

DIY Router

Pros:

Cons:

Example from my todo app:

import { useState } from 'react';

enum PAGES {
  HOME,
  SETTINGS
}

export function Router() {
  const [currentPage, setCurrentPage] = useState(PAGES.HOME)

  return (
    <>
      <div>
        <button onClick={() => setCurrentPage(PAGES.HOME)}>home</button>
        <button onClick={() => setCurrentPage(PAGES.SETTINGS)}>settings</button>
      </div>

      {currentPage === PAGES.HOME && 'home page'}
      {currentPage === PAGES.SETTINGS && 'settings page'}
    </>
  );
}

Right now this is sufficient.