How to navigate to path with param in App directory?
Answered
Rule posted this in #help-forum
RuleOP
Hi. I'm trying to navigate to a path with param in app directory.
My page file is located:
What is the equivalent to this pages directory code for app directory?
I would prefer not to use syntax like this:
My page file is located:
/app/user/[userId]/page.tsxWhat is the equivalent to this pages directory code for app directory?
import { useRouter } from "next/router";
const router = useRouter();
const userId = 1;
router.push({ pathname: router.pathname, query: { userId } });I would prefer not to use syntax like this:
router.push("/user/1")Answered by riský
yeah thats what they say: https://nextjs.org/docs/app/api-reference/functions/use-router#migrating-from-nextrouter
7 Replies
that is the way tho (
router.push("/user/1"))RuleOP
I have a few other routes inside the [userId] directory so I have paths like this:
/user/1/something or /user/1/something-else. I want to be able to update the user id inside those pages while keeping the same routeI mean I could get the current path and modify the string manually but just wondering if there is a correct way to do it
yeah thats what they say: https://nextjs.org/docs/app/api-reference/functions/use-router#migrating-from-nextrouter
Answer
RuleOP
Yea. I guess there is no support for the previous syntax anymore.
Thanks for the help
@Rule Thanks for the help
no problem, and thats sad that they don't have that (i kinda forgot about that syntax)