W
Wasp-lang2mo ago
NEROX

Hide Loged User Navigation Bar in Onboarding Page

Heyy @kapa.ai I created an onboarding page, that is when the user comes from the register, I want to hide the navigation bar only for this page, I'm working with the SaaS template
10 Replies
kapa.ai
kapa.ai2mo ago
Hi @NEROX. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To hide the navigation bar on a specific page, you can create a separate layout for that page without the navigation bar. In Wasp, the layout is usually defined in a file like Layout.jsx or Layout.tsx and it includes the navigation bar. You can create a new layout file without the navigation bar and use it for your onboarding page. Here is an example of how you can do it: 1. Create a new layout file, let's call it OnboardingLayout.jsx (or OnboardingLayout.tsx if you are using TypeScript), without the navigation bar. 2. In your main.wasp file, when declaring your onboarding page, use the new layout:
page OnboardingPage {
component: import Onboarding from "@src/pages/Onboarding",
layout: import OnboardingLayout from "@src/OnboardingLayout"
}
page OnboardingPage {
component: import Onboarding from "@src/pages/Onboarding",
layout: import OnboardingLayout from "@src/OnboardingLayout"
}
Please note that this is a general approach and might need to be adjusted based on your specific project setup. For example, in the OpenSaaS template, the landing page has its own navbar component, so you might need to adjust your approach based on how the template is structured (source (https://discord.com/channels/686873244791210014/1215258301780987904)). If you need to show or hide certain elements based on whether the user is logged in or not, you can use the useAuth hook to get the current user and then conditionally render elements based on whether the user is null/undefined or not (source (https://discord.com/channels/686873244791210014/1215258301780987904)). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @NEROX, 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?
NEROX
NEROXOP2mo ago
@kapa.ai Unexpected dictionary field 'layout' 474 | route OnboardingRoute { path: "/onboarding", to: OnboardingPage } 475 | page OnboardingPage { 476 | component: import { OnboardingPage } from "@src/onboarding/OnboardingPage", 477 | authRequired: true, 478 | layout: import OnboardingLayout from "@src/OnboardingLayout" 479 | }
kapa.ai
kapa.ai2mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- I'm sorry for the confusion, but currently, Wasp doesn't support the layout field in the page declaration. The error you're seeing is because the Wasp compiler doesn't recognize layout as a valid field in a page declaration. As a workaround, you can conditionally render the navigation bar in your main layout based on the current route. You can use the useLocation hook from react-router-dom to get the current route, and then conditionally render the navigation bar based on that. Here's a simplified example:
import { useLocation } from 'react-router-dom'

export function MainLayout({ children }) {
const location = useLocation()

return (
<div>
{ location.pathname !== '/onboarding' && <Navbar /> }
{ children }
</div>
)
}
import { useLocation } from 'react-router-dom'

export function MainLayout({ children }) {
const location = useLocation()

return (
<div>
{ location.pathname !== '/onboarding' && <Navbar /> }
{ children }
</div>
)
}
In this example, the Navbar component will not be rendered when the current route is /onboarding. Please note that this is a general approach and might need to be adjusted based on your specific project setup. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @NEROX, 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?
NEROX
NEROXOP2mo ago
@kapa.ai ✅ Fixed! It was what I wanted but I have not counted on the theme swicher disappearing, since it is in the nav bar and the default theme is set to clear. How could I keep the theme swicher component and the log component out on the onboarding page?
kapa.ai
kapa.ai2mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- You can create a separate component for the theme switcher and the log component and include them in your main layout outside of the conditional rendering block. This way, they will always be rendered, regardless of the current route. Here's a simplified example:
import { useLocation } from 'react-router-dom'

export function MainLayout({ children }) {
const location = useLocation()

return (
<div>
{ location.pathname !== '/onboarding' && <Navbar /> }
<ThemeSwitcher />
<LogComponent />
{ children }
</div>
)
}
import { useLocation } from 'react-router-dom'

export function MainLayout({ children }) {
const location = useLocation()

return (
<div>
{ location.pathname !== '/onboarding' && <Navbar /> }
<ThemeSwitcher />
<LogComponent />
{ children }
</div>
)
}
In this example, the Navbar component will not be rendered when the current route is /onboarding, but the ThemeSwitcher and LogComponent will always be rendered. Please note that this is a general approach and might need to be adjusted based on your specific project setup. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @NEROX, 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?
NEROX
NEROXOP2mo ago
@kapa.ai What file should this file be?
kapa.ai
kapa.ai2mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- The code should be placed in your main layout file. This is typically named Layout.jsx or Layout.tsx and is located in the src directory of your Wasp project. This file is responsible for defining the layout of your application, including the navigation bar, theme switcher, log component, and other common elements. Here's an example of how your Layout.jsx file might look:
import React from 'react'
import { useLocation } from 'react-router-dom'
import Navbar from './Navbar'
import ThemeSwitcher from './ThemeSwitcher'
import LogComponent from './LogComponent'

const Layout = ({ children }) => {
const location = useLocation()

return (
<div>
{ location.pathname !== '/onboarding' && <Navbar /> }
<ThemeSwitcher />
<LogComponent />
{ children }
</div>
)
}

export default Layout
import React from 'react'
import { useLocation } from 'react-router-dom'
import Navbar from './Navbar'
import ThemeSwitcher from './ThemeSwitcher'
import LogComponent from './LogComponent'

const Layout = ({ children }) => {
const location = useLocation()

return (
<div>
{ location.pathname !== '/onboarding' && <Navbar /> }
<ThemeSwitcher />
<LogComponent />
{ children }
</div>
)
}

export default Layout
In this file, Navbar, ThemeSwitcher, and LogComponent are assumed to be other components in your project. You would replace these with the actual components you're using for these parts of your layout. The children prop is where the content of individual pages will be inserted. Please note that this is a general approach and might need to be adjusted based on your specific project setup. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @NEROX, 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?
NEROX
NEROXOP2mo ago
@kapa.ai Done but not appear: import AppNavBar from './components/AppNavBar'; import CookieConsentBanner from './components/cookie-consent/Banner'; import { useMemo, useEffect, ReactNode } from 'react'; import { useLocation } from 'react-router-dom'; import { NextUIProvider } from "@nextui-org/system"; export default function App({ children }: { children: ReactNode }) { const location = useLocation(); const { data: user } = useAuth(); const shouldDisplayAppNavBar = useMemo(() => { return location.pathname !== '/' && location.pathname !== '/login' && location.pathname !== '/signup' && location.pathname !== '/onboarding'; // Añadimos la ruta de onboarding }, [location]);
kapa.ai
kapa.ai2mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- It seems like you have defined the shouldDisplayAppNavBar variable correctly, but you haven't used it to conditionally render the AppNavBar component. You should use this variable in your JSX to decide whether to render the AppNavBar or not. Here's how you can do it:
import AppNavBar from './components/AppNavBar';
import CookieConsentBanner from './components/cookie-consent/Banner';
import { useMemo, useEffect, ReactNode } from 'react';
import { useLocation } from 'react-router-dom';
import { NextUIProvider } from "@nextui-org/system";

export default function App({ children }: { children: ReactNode }) {
const location = useLocation();
const { data: user } = useAuth();

const shouldDisplayAppNavBar = useMemo(() => {
return location.pathname !== '/' &&
location.pathname !== '/login' &&
location.pathname !== '/signup' &&
location.pathname !== '/onboarding'; // Añadimos la ruta de onboarding
}, [location]);

return (
<NextUIProvider>
{ shouldDisplayAppNavBar && <AppNavBar /> }
<CookieConsentBanner />
{ children }
</NextUIProvider>
);
}
import AppNavBar from './components/AppNavBar';
import CookieConsentBanner from './components/cookie-consent/Banner';
import { useMemo, useEffect, ReactNode } from 'react';
import { useLocation } from 'react-router-dom';
import { NextUIProvider } from "@nextui-org/system";

export default function App({ children }: { children: ReactNode }) {
const location = useLocation();
const { data: user } = useAuth();

const shouldDisplayAppNavBar = useMemo(() => {
return location.pathname !== '/' &&
location.pathname !== '/login' &&
location.pathname !== '/signup' &&
location.pathname !== '/onboarding'; // Añadimos la ruta de onboarding
}, [location]);

return (
<NextUIProvider>
{ shouldDisplayAppNavBar && <AppNavBar /> }
<CookieConsentBanner />
{ children }
</NextUIProvider>
);
}
In this code, the AppNavBar component will only be rendered if shouldDisplayAppNavBar is true. If the current route is '/', '/login', '/signup', or '/onboarding', shouldDisplayAppNavBar will be false and the AppNavBar will not be rendered. Please note that this is a general approach and might need to be adjusted based on your specific project setup. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @NEROX, 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?
NEROX
NEROXOP2mo ago
✅ Fixed ma boi
Want results from more Discord servers?
Add your server