Change tab title to what page user is on
how do i change tab title to what page the user is on? for example "SaaS - Dasboard"
11 Replies
Hi @Sven. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To change the tab title dynamically based on the current page in a Wasp application, you have a few options:
Using the Root Component
The most flexible approach is to use Wasp's root component feature to set up a custom title management system:
1. First, set up a root component in your
main.wasp
file:
2. Then implement your Root component with title management:
This approach uses the root component to wrap your entire application and update the document title whenever the location changes. The root component is a perfect place for this kind of functionality as explained in the Client Config documentation.
Alternative: Page-specific Title Updates
You can also update the title directly in each page component:
This approach works well if you have a small number of pages and prefer to keep the title logic with each page component.
Choose the approach that best fits your application structure and complexity.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Sven, 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?Oh i've never thought about this actually. Did this work @Sven?
Maybe @toticozeni can take a look at this and chime in.
It worked
Oh, it looks like we are missing title property for page. We should definitely open an issue for that.
The suggested
Root
solution works, but I would do something like this, it should be easier to maintain:
The problem with Root
approach is that we need to manually update the object each time we add another page. But it's less work than doing useEffect
on each Page.
EDIT: added Vinny's suggestionSo i have ti update manyally for each page?
Do it for every page in
Root
or do it manually on each page.
Both work.we have also the
react-helmet-async
solutionYou could also make it more typesafe by using Wasp routes. It will pull the path you defined in your wasp file. Also nice if you decided to change it later, you won't have to change it in other places in your code:
woah, since when is this possible?
we've had typesafe routes for a long time 🙂
This would probably be the most scalable solution longterm.