#Hello someone know how to get current
1 messages · Page 1 of 1 (latest)
Hi @wary quiver. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
@proven peak
Sorry @wary quiver, I seem to be having a bit of trouble. Don't worry though, I've pinged my supprt and they will try to fix me up! :technologist:
Perhaps try again in 15mins?
Let me check the knowledge base for you. One moment! :books:
Sorry @wary quiver, I seem to be having a bit of trouble. Don't worry though, I've pinged my supprt and they will try to fix me up! :technologist:
Perhaps try again in 15mins?
server component sorry
const { req, query, res, asPath, pathname } = context;
I have a sidebar and the only reason i have 'use client' is a usePath on my items to know if it's active item
ok hang on.
context is available in server components ?
import { useRouter, usePathname, useSearchParams } from 'next/navigation';
no you have to use the new router from nextNavigation!
usePathname is not available in server component :/
so i have to keep my use client ?
as far as i know you cant really access the request object in the nextjs13, the only things you can extract are the headers and the cookies of a request.
ohh okay..
so the only workaround which people use is using the middleware of nextjs13 and setting the url on the header and returning it
on the server component you can then fetch the url which was set in the header from the middleware.
idk why it isnt implemented yet tbh
i already use a middleware for translations, i never work with multple middlewares, it's possible ?
yeah I just checked, middleware is how I did it as well...
its a bit of a hackery tbh...
what do you mean multiple?
i see, thank you for your investigations
i have a middleware file in my root project directory
you can do that in one file, you can also do some operations only on specific paths by checking the pathname of the request if you mean that.
this middleware is for my translations, but if i have to transform request i want to separate the logic in another middleware file
yeah not possible currently, nextjs allows only one middleware file in the root directory
okay i see
i mean you can split your utility functions into own modules to make it cleaner
just check, how the middleware is used for i18n. It actually checks for certain routes and leaves out some to not mess with loading images for example. This way you can do stuff on other routes as well.
it's not mine middleware..
import createIntlMiddleware from 'next-intl/middleware'
import i18nConfig from '@/settings/i18n'
export default createIntlMiddleware({
...i18nConfig,
})
it's the i18n middleware provided by the library quoted in the nextjs documentation
i cannot custom this