NextResponse. redirect vs rewrite
Answered
Southeastern blueberry bee posted this in #help-forum
Southeastern blueberry beeOP
Can anyone explain me the difference between redirect and rewrite method of nextresponse and when should I use one over another with some use case thank you ?
Answered by B33fb0n3
redirect redirects the user to a new url. Example: User visits /hello and will be redirected to /world. The url for the user is now /world
rewrite works the same, but the url for the user will stay the old one. Example: User visits /hello and this route will be rewritten to /world. The url for the user is now still /hello, but the content of /world is loaded
rewrite works the same, but the url for the user will stay the old one. Example: User visits /hello and this route will be rewritten to /world. The url for the user is now still /hello, but the content of /world is loaded
3 Replies
@Southeastern blueberry bee Can anyone explain me the difference between redirect and rewrite method of nextresponse and when should I use one over another with some use case thank you ?
redirect redirects the user to a new url. Example: User visits /hello and will be redirected to /world. The url for the user is now /world
rewrite works the same, but the url for the user will stay the old one. Example: User visits /hello and this route will be rewritten to /world. The url for the user is now still /hello, but the content of /world is loaded
rewrite works the same, but the url for the user will stay the old one. Example: User visits /hello and this route will be rewritten to /world. The url for the user is now still /hello, but the content of /world is loaded
Answer
@B33fb0n3 redirect redirects the user to a new url. Example: User visits /hello and will be redirected to /world. The url for the user is now /world
rewrite works the same, but the url for the user will stay the old one. Example: User visits /hello and this route will be rewritten to /world. The url for the user is now still /hello, but the content of /world is loaded
Selkirk Rex
really interesting piece of info