// Import the necessary modules from Next.js
import { useRouter } from 'next/router';
// Create a functional component
const MyComponent = () => {
// Get the router object
const router = useRouter();
// Define the function to handle button click
const handleClick = () => {
// Use the router object to push a new route to the history
router.push('/new-route');
};
// Return JSX with a button that triggers the handleClick function on click
return (
<div>
<button onClick={handleClick}>Change Route</button>
</div>
);
};
// Export the component
export default MyComponent;