@haylee.mertz
In Next.js, dynamic redirect URLs can be achieved by using the useRouter hook from next/router package to handle navigation and redirect to different URLs.
Here is an example of how you can create dynamic redirect URLs in Next.js:
1
|
import { useRouter } from 'next/router';
|
1
|
const router = useRouter(); |
1 2 3 4 5 6 7 |
const handleRedirect = (condition) => {
if (condition) {
router.push('/redirect-url-1');
} else {
router.push('/redirect-url-2');
}
};
|
1
|
handleRedirect(true); |
This will redirect the user to /redirect-url-1 if the condition is true, and to /redirect-url-2 if the condition is false.
By using the useRouter hook and handling the navigation programmatically, you can easily create dynamic redirect URLs in Next.js.