Last 12 weeks · 0 commits
I have noticed kind of difference between both link components: NextJs Link and Router Link. Once a Router Link is clicked, a response can be seen by the user, since it changes the page inmediately. Some time it will take for data being fetched after page changes. In other context, once a NextJS Link is clicked, it takes a time for a response to be shown in the UI meanwhile NextJS fetches data to "avoid refreshing the whole page". As data arrives to the client, the wanted page renders to the screen. The difference: Router reacts first and waits later. NextJS waits first and reacts later. This can be perceived with slow networks. Offering reactive events to the user on SPAs developed with Router, and more sensitive feeling, while those NextJS based Multi Page Apps having the user with uncertainty and clicking the link many times awaiting for a UI reaction.
This example breaks attempting to nest URLs for correct routing with react router. Sandbox here: https://codesandbox.io/s/next-js-react-router-demo-w1y6x Ive added two pages - one with non-nested links (so react router overwrites next js URLS) and one attempting correct nested URLs in the address bar. The mnested routes using useRouteMatch dont work i guess because they are not tracking Next routers URL paths. ``` import React from "react"; import { BrowserRouter as Router, Switch, Route, Link, useRouteMatch } from "react-router-dom"; import NextLink from "next/link"; const Routed = () => { let { path, url } = useRouteMatch(); console.log(path, url); return ( <> Home (SSR) Test (SSR) Link one (SPA) Link two (SPA) Page one Page two ); }; export default function App() { return ( ); } Is there a way to support combinations of next/RR URLs and paths?
Repository: colinhacks/nextjs-react-router. Description: A demonstration of how to use React Router inside Next.js Stars: 159, Forks: 30. Primary language: TypeScript. Homepage: https://vriad.com/essays/building-a-spa-with-nextjs Topics: nextjs, react-router, spa. Open PRs: 0, open issues: 5. Last activity: 3y ago. Top contributors: colinhacks.