Using app router to dynamically change url params
Unanswered
Siricid woodwasp posted this in #help-forum
Siricid woodwaspOP
In the pages router this is easy:
In the app router I need to go over hoops and loop to do the same. Am i missing anything?
const {asPath, replace} useRouter()
replace(asPath, asPath, {[paramName]: newValue})
In the app router I need to go over hoops and loop to do the same. Am i missing anything?
2 Replies
Siricid woodwaspOP
for context, i used this to manage my locales:
Now i need to both write it myself and dont have the built it locale option, and need to manually add it.
const { locale, asPath, replace } = useRouter();
return (
<nav className={styles.nav}>
<Switch
id="language-selector"
checked={locale === "en"}
onChange={() => {
replace(asPath, asPath, { locale: locale === "en" ? "he" : "en" });
}}
selectedText={"En"}
unselectedText={"עב"}
/>
</nav>
);
Now i need to both write it myself and dont have the built it locale option, and need to manually add it.
this feels to me like the app router is a step back in those regards