Installing and Basic Configuration of TanStack Router
Demonstrate how to install TanStack Router via npm and set up a basic routing configuration with a root route and a 404 not found route.
// Install TanStack Router via npm
npm install @tanstack/react-location
This command installs the TanStack Router package using npm.
import { createBrowserRouter, RouterProvider, Route } from '@tanstack/react-location';
// Define your routes
const router = createBrowserRouter([
{ path: '/', element: <HomePage /> },
{ path: '*', element: <NotFoundPage /> }
]);
function App() {
return (
<RouterProvider router={router} />
);
}
Set up a basic routing configuration with a root route (HomePage) and a 404 Not Found route (NotFoundPage).