const router = useRouter(); // get the router/location object
const information = useFetch({ position: router.query.position }); // fetch information from the server
function changeChessPosition(newPosition) { // called when position changes
router.replace({ query: { postition: newPosition } }); // replaces the state in the URL
}
In addition, I have some caching in place so that each position is only downloaded once and the change function looks a little more complicated in my case as there are multiple values that can be change for each page.
All data comes from my project ChessMonitor, which maintains one of the largest chess databases in the world. Feel free to check it out! :)