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
-
Above you can see snippet of code from
next.js
_middleware.ts
, I see thatFresh
also 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/home
I want to see it on/home
. Is it possible ?Beta Was this translation helpful? Give feedback.
All reactions