#Using Nav.Link

1 messages · Page 1 of 1 (latest)

frozen crane
#

your navbar needs to be rendered inside the router

#

do you have a <Router>? do any links work?

twilit sigil
twilit sigil
#

Links arent showing up due to that error

frozen crane
#

ok, and just making sure, you are using React Router and not Remix, correct?

twilit sigil
#

Correct

frozen crane
#

and this is RR 6.4?

#

do you have a <RouterProvider> like it says in the tutorial?

#

that error could stand to be updated, it's now <RouterProvider> and not <Router>

twilit sigil
#

I believe I have 6.4

twilit sigil
#

in main.tsx?

frozen crane
#

yeah, I mean basically you want it at the top level of your app where you call React's render()

#

you need to call

const router = createBrowserRouter([ /* route config */ ])

and set up your route config there, and pass that to RouterProvider

twilit sigil
#

Im trying that now

#

i will let u know

twilit sigil
frozen crane
#

what did you pass in to createBrowserRouter as the route config?

twilit sigil
#
const router = createBrowserRouter([
  {
    path: "/",
    element: <App />,
    children: [
      {
        path: "/home",
        element: <Home />,
      },
      {
        path: "/about",
        element: <About />,
      },
      {
        path: "/store",
        element: <Shop />,
      },
    ]
  }
])

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
  <RouterProvider
    router={router}
    fallbackElement={<App />}
  />
)
frozen crane
#

children means routes underneath a path segment. so if you wanted /abc and /abc/def you could either do

[ 
  { 
    path: 'abc',
    children: [{ path: "def" }] 
  }
]

or

[ 
  { path: 'abc' },
  { path: 'abc/def' },
]
twilit sigil
#

oh!

frozen crane
#

I'm guessing your <App> doesn't have an outlet

#

what's in it

#

the outlet is where the children would render

twilit sigil
#

it only has <Navbar /> & Container

frozen crane
#

ah that makes sense then. put <Outlet /> in the container

#

home, about, and shop will show up in there

twilit sigil
#

from router?

frozen crane
#

don’t know what you mean

twilit sigil
#

It doesn't know what Outlet is from

frozen crane
#

you have to import it from react-router-dom

twilit sigil
#

that is what i meant, when I said from router. Sorry

frozen crane
#

it is really better to start from what the tutorial says to do

#

then add your pages to something that’s already working

twilit sigil
#

Links are not showing up. I will figure it out. Im rushing it.