Rewrite path for mobile and desktop folders #2093
Closed
andriiradkevych
started this conversation in
General
Replies: 1 comment 9 replies
-
|
Something like this should work. function myMiddleware(req: Request) {
const prefix = isMobile(req) ? "/mobile" : "/desktop"
const url = new URL(req.url)
const newUrl = new URL(`${prefix}${url.pathname}, url.origin).href
return Response.redirect(newURL.href)
} |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Above you can see snippet of code from
next.js_middleware.ts, I see thatFreshalso have_middleware, but is it possible to do the same ?Why do I want to make it ?
I want to make 2 different versions of site for mobile and desktop , detect which device are used on
_middleware, and return version of site related to this , but I don't need to have it on path/mobile/homeI want to see it on/home. Is it possible ?Beta Was this translation helpful? Give feedback.
All reactions