Next.js Discord

Discord Forum

I'm trying to retrieve the current URL path and extract a specific part of it.

Answered
Abert's Towhee posted this in #help-forum
Open in Discord
Avatar
Abert's TowheeOP
Scenario:
When a user visits a URL like "http://localhost:3000/category/Cars?search=Toyota", I need to get the full path after "/category/Cars", which is "?search=Toyota".
I will use the provided value to perform a search for users

What I've tried:
import { usePathname } from 'next/navigation'
const pathname = usePathname()
but based on the docs it would only return 'Category' or 'Cars'
&&
export default async function Page({ params }: { params: { slug: string } }) {
const { slug } = params;
Same problem here,

Issue:
Im not sure how to move around the issue

Question:
How can I extract the full path after "/category/Cars" from the current URL in a Next.js application using Supabase?
Answered by Abert's Towhee
var search = window.location.search
View full answer

2 Replies

Avatar
Abert's TowheeOP
var search = window.location.search
Answer
Avatar
Abert's TowheeOP
nvm i got it