Next 14 Route Params
Unanswered
Alaska pollock posted this in #help-forum
Alaska pollockOP
I have a redriect url e.g. http://localhost:3000/festival?code=123
My compoennt renders. What's the best approach to get the route code '123' in this scenario? Can this be done in a server component or should it be done in a client component?
This is an example Im trying and failing to do with a client component.
My compoennt renders. What's the best approach to get the route code '123' in this scenario? Can this be done in a server component or should it be done in a client component?
This is an example Im trying and failing to do with a client component.
'use client';
import { useEffect, useState } from 'react';
import { useParams } from 'next/navigation';
import { useRouter } from 'next/router';
export default function FestivalPage() {
const router = useRouter();
const params = useParams();
const [topArtists, setTopArtists] = useState(null);
useEffect(() => {
const code = params.code;
console.log("params",params)
console.log("params.code",params.code)
if (code) {
exchangeCodeForToken(code);
}
}, [params]);1 Reply
Plott Hound
I think it would easier to make the path festival/123 then you can just use the params prop to directly access it in a dynamic route.
If you’re set on using the ? You’d have to do it client side I think
https://nextjs.org/docs/app/api-reference/functions/use-search-params
If you’re set on using the ? You’d have to do it client side I think
https://nextjs.org/docs/app/api-reference/functions/use-search-params