W
Wasp-lang•3w ago
N

Does wasp support preceeding route param eg. "/:lang/dashboard" ?

I want to have pages in different languages so i would like to set up the following routes: /:lang/dashboard /:lang/account ... If not, what can I do as a workaround? thanks!
3 Replies
MEE6
MEE6•3w ago
Wohooo @N, you just became a Waspeteer level 1!
kapa.ai
kapa.ai•3w ago
Hi @N. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, Wasp does support preceding route parameters like "/:lang/dashboard". You can add parameters to the URL path using the same syntax as React Router. Here's an example from the Wasp tutorial:
route HelloRoute { path: "/hello/:name", to: HelloPage }
page HelloPage {
component: import { HelloPage } from "@src/HelloPage"
}
route HelloRoute { path: "/hello/:name", to: HelloPage }
page HelloPage {
component: import { HelloPage } from "@src/HelloPage"
}
In your case, you can set up your routes like this:
route DashboardRoute { path: "/:lang/dashboard", to: DashboardPage }
page DashboardPage {
component: import { DashboardPage } from "@src/DashboardPage"
}

route AccountRoute { path: "/:lang/account", to: AccountPage }
page AccountPage {
component: import { AccountPage } from "@src/AccountPage"
}
route DashboardRoute { path: "/:lang/dashboard", to: DashboardPage }
page DashboardPage {
component: import { DashboardPage } from "@src/DashboardPage"
}

route AccountRoute { path: "/:lang/account", to: AccountPage }
page AccountPage {
component: import { AccountPage } from "@src/AccountPage"
}
When a user visits "/en/dashboard" or "/fr/account", Wasp will render the corresponding component and pass the URL parameter (lang) the same way as in React Router. You can then use this lang parameter to display the page in the appropriate language. For more details, you can refer to the Wasp tutorial on adding a second page (https://wasp-lang.dev/docs/tutorial/pages#adding-a-second-page). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @N, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
miho
miho•3w ago
Have you tried it and it didn't work? 🙂 That seems like the best way to find out if it'll work. I believe it should work, we are using the React Router library under the hood for routing.
Want results from more Discord servers?
Add your server