#skip sub-path in link component

29 messages · Page 1 of 1 (latest)

tawny crypt
#

Is there a way i can skip a sub-path because its dynamic and i dont want to get the data for it everyime so can i do:

<Link href={"/**/dashboard"}>

or something similar?

raw cedarBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

sonic venture
tawny crypt
#

hmmm

#

The issue is that i just implemented internationalization

sonic venture
tawny crypt
#

and to get the locale i would need to be in a server component because it needs to be awaited so i can then use the locale in the link

#

yes, it does

#

my issue is with normal links

#

when the path was before:

localhost:3000/dashboard

it doesnt work anymore but should be:

localhost:3000/(locale)/dashboard

snow rock
#

Can’t you use useParams() to get it in client components?

sonic venture
# tawny crypt and to get the locale i would need to be in a server component because it needs ...

So with internationalization it would look like this:

So if you are on

https://localhost:3000/en/world/main

And you link to

world/second

You will be redirect to

https://localhost:3000/en/world/second

Without rewriting en again.

Or if you need to provide a path beginning with / you can do it like that:

https://localhost:3000/en/world/main

And you link to

/world/second

You will be redirect to

https://localhost:3000/world/second

Your middleware will catch, that there is no internationalization in it and redirect to

https://localhost:3000/en/world/second
tawny crypt
tawny crypt
tawny crypt
#

but i will have a look in my middleware tho

#

Because its quite tedious to do useParams in every file i want to use a link component

sonic venture
#

yea, joulev's way is a fast way. The way I mentioned is an effective way

tawny crypt
#

do you know how i can default export these 2? because i need the auth and the intl:

import { authMiddleware } from "@clerk/nextjs"

import createMiddleware from "next-intl/middleware"

export default authMiddleware({
  // Allow signed out users to access the specified routes:
  publicRoutes: ["/", "/api/getCollabToken/[userId]"],
  ignoredRoutes: ["/tutorial/(.*)", "/api"],
})

export default createMiddleware({
  // A list of all locales that are supported
  locales: ["en", "de"],

  // Used when no locale matches
  defaultLocale: "en",
})

export const config = {
  // Match only internationalized pathnames
  matcher: [
    "/((?!.+\\.[\\w]+$|_next).*)",
    "/(api|trpc)(.*)",
    "/",
    "/(de|en)/:path*",
  ],
}
#

(before i removed the export default from the authMiddleware but then this error came:)

Unable to find `next-intl` locale because the middleware didn't run on this request. See https://next-intl-docs.vercel.app/docs/routing/middleware#unable-to-find-locale. The `notFound()` function will be called as a result.
sonic venture
#

I am not into clerk middleware, sorry. If you know how to check for public and dingoredRoutes inside a normal middleware, you can directly add the internationalization part to it. Like that you merged both actions in one middelware

tawny crypt
#

Still thanks a Lot tho ❤️

sonic venture
tawny crypt
#

Doesnt Work on Phone 😭

sonic venture
#

If you hold your finger on the message you still get the „Apps“

tawny crypt
#

Yep but then it says no commands available

sonic venture
#

lol @snow rock would you mark the correct message?

tawny crypt
#

I already refreshed the app

raw cedarBOT
#
✅ Success!

This question has been marked as answered! If you have any other questions, feel free to create another post

Jump to answer