migrate issues with app router
Unanswered
Sun bear posted this in #help-forum
Sun bearOP
I have a select that changes language with onChange like this
onChange={(e) =>
router.push({ pathname, query }, asPath, {
locale: e.target.value,
})
} im trying to achieve the same result as before with app router too but i have no clue36 Replies
Asian black bear
The most expedient way would be to put the language change button component into its own file marked 'use client'
Sun bearOP
use client part is im ok with it problem starts with this they removed aspath query pathname etc from router object in app
Asian black bear
Yes, I suppose that does make sense. asPath would not work so great with server components
do you not want to have the language tagged anywhere in the URL?
Sun bearOP
i actually want it :/
Asian black bear
hmmm, it looks like they just want you to use a middleware for internationalization https://nextjs.org/docs/app/building-your-application/routing/internationalization#routing-overview
this looks like a very big project for you ðŸ˜
Sun bearOP
nah middleware part does not make it sense since if a user lets say from france wants it to use it with english they should not stuck with french tho
Asian black bear
I actually agree, but you could just link from
/fr/page to /en/page in this examplethe middleware only switches if there is no language path tag
<Link> for dynamic paths lets you just put the resolved path in the strin gyou dont have to do the stuff with
/[locale]/page asPath=/en/page ...@Asian black bear I actually agree, but you could just link from `/fr/page` to `/en/page` in this example
Sun bearOP
i do that stuff for select sadly select onChange={(e) =>
router.push({ pathname, query }, asPath, {
locale: e.target.value,
})
}
router.push({ pathname, query }, asPath, {
locale: e.target.value,
})
}
lets say that switch a the locale in middle of a route in pages route it switches where there user they are and thats a nice ux but if im gonna switch lang prob i need to send to root page right?
Asian black bear
I would switch to the equivalent page if such a page exists, or dump them to the home page otherwise
and if they don't like that they can hit the back button
Sun bearOP
the original part how i handle the switch
Asian black bear
yeah, that makes sense entirely
Sun bearOP
so, how do i do it with your way looking to docs they didn't mentioned switching locales with link component
Asian black bear
so, basically next.js has gotten rid of the localization feature in the app directory as it is redundant with the release of middleware
you have to put the middleware from the linked page, and then the router.push just takes a plain ol' url for the page with a language tag if you want to switch
Sun bearOP
do they added rsc to pages too right?
@Asian black bear
Asian black bear
like pages in the
/pages dir and not the /app dir?Sun bearOP
yeah
Asian black bear
no, everything in
/pages works exactly the same as Next 12 basicallyand also no, the stuff in
/app and in /pages are totally separate, almost like two separate React appsSun bearOP

Asian black bear
that is what I meant that it will be a lot of work, it doesn't look like there is an incremental upgrade path
I am working on ripping the Redux out of an app to port it
@Asian black bear that is what I meant that it will be a lot of work, it doesn't look like there is an incremental upgrade path
Sun bearOP
yeah i know just asked to be sure i guess if they ever remove it i will probably switch
or stick with the current version that im using
or stick with the current version that im usingAsian black bear
I was getting pretty serious about svelte in the interim before the
/app thing was marked stable, but ultimately came back due to a lack of supporting librariesSun bearOP
in my project i already have a seperate backend, later on if they kill it i will just get rid of the next js totally and add react or svelte to directly backend to create achiving ssr i guess 

those my options since i tried today the app router whats the benefit of using to test it
for my case None 

Asian black bear
good luck!