SolidJSS
SolidJSโ€ข9mo agoโ€ข
15 replies
indigo.snowboll

Same route for private and protected content

Hi,

Is there a way to have a single route show different content depending on the user being logged in or not?

I came up with this, but I'm pretty sure it's incorrect:

export default function PublicLayout(props: RouteSectionProps) {
  const user = createAsync(() => getUser());
  const location = useLocation();

  return (
    <MetaProvider>
      <Switch
        fallback={
          {/* Public content */}
          <Suspense>{props.children}</Suspense>
        }
      >
        <Match when={location.pathname === '/' && !user()}>
          {/* Public home page */}
          <Suspense><HeroPage /></Suspense>
        </Match>
        <Match when={location.pathname === '/' && user()}>
          {/* Protected home page */}
          <Suspense><Home /></Suspense>
        </Match>
      </Switch>
    </MetaProvider>
  );
}


Any hints welcome!
Was this page helpful?