How to detect if I reached the current directly by a normal navigation (or url) vs via `redirect` ?
Unanswered
American Curl posted this in #help-forum
American CurlOP
I have a page under
When I add
or
I don't really receive any info about the
/hi I reach this either by a normal navigation through Next.js link or direct link OR a redirect now - how can I differentiate?When I add
redirect: {
destination: "/upload",
permanent: false,
},or
redirect: {
destination: "/upload",
statusCode: 307,
},I don't really receive any info about the
307 redirect!!1 Reply
That depends on where you want to detect this.
Technically they have no difference for the client side. Doesn't matter which page the client is fetching, they'll be redirected to "hi". Javascript can't be executed cross redirections due to browser behavior. On other hands, you can't detect this in client-side javascript.
On the server side, you might have to redirect with a middleware, since
Technically they have no difference for the client side. Doesn't matter which page the client is fetching, they'll be redirected to "hi". Javascript can't be executed cross redirections due to browser behavior. On other hands, you can't detect this in client-side javascript.
On the server side, you might have to redirect with a middleware, since
redirect in next.config.js is handled by Next.js internally. You have no ability to detect or execute code on redirecting users.