Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

useRoutes

// React Router v6:
// hook functionally equivalent to <Routes>, but uses JS objects instead
// of <Route>, use this hook instead of 'react-router-config' (React Router v5)
import { useRoutes } from 'react-router-dom';

function App() {
  let element = useRoutes([
    {
      path: '/',
      element: <Dash />,
      children: [
        { path: 'messages', element: <DashMessages /> },
        { path: 'tasks', element: <DashTasks /> }
      ]
    },
    { path: 'team', element: <About /> }
  ]);

  return element;
}
Comment

useroutes how to use

//routes.js

import { useRoutes } from "react-router-dom";
import Home from './pages/Home'
import About from './pages/About'
import Login from './pages/Login'
import SignUp from './pages/Signup'
import AuthLayout from './layouts/AuthLayout'
import MainLayout from './layouts/MainLayout'

export default function Router() {
  let element = useRoutes([
      {
          element: <AuthLayout />,
          children: [
             { path: "/", element: <Login /> },
             { path: "signup", element: <SignUp /> },
          ],
      },
      {
          element: <MainLayout />,
          children: [
              { path: "home", element: <Home /> },
              { path: "about", element: <About /> },
          ],
      },
  ]);
  return element;
}

//App.js

import "./styles.css";
import { BrowserRouter } from "react-router-dom";
import Router from './routes'

export default function App() {
  return (
      <BrowserRouter>
          <div className="App">
              <h1>useRoutes Example</h1>
              <Router/>
          </div>
      </BrowserRouter>
  );
}

//link to full example
//https://codesandbox.io/s/thirsty-architecture-jgok5?file=/src/App.js
Comment

PREVIOUS NEXT
Code Example
Javascript :: using ontimeupdate in javascript 
Javascript :: append string javascript 
Javascript :: object promise javascript 
Javascript :: delete message plugin discord 
Javascript :: how to get the text from an input field 
Javascript :: react: fow to use find(to get the id of a element 
Javascript :: javascript sort 
Javascript :: how to connect mongodb with next js 
Javascript :: js error handling 
Javascript :: radio button not checked 
Javascript :: navigate json object javascript 
Javascript :: Ping discord 
Javascript :: in javascipt how to stop further page processing 
Javascript :: defining schema mongoose 
Javascript :: jquery get element by tag 
Javascript :: how to find element in array angularjs 
Javascript :: angular custom directive 
Javascript :: add column sequelize 
Javascript :: javascript copy object 
Javascript :: variable in js 
Javascript :: jsx return greatest number between two numbers 
Javascript :: 10 javascript interview questions 
Javascript :: d3 force simulation 
Javascript :: csurf in express 
Javascript :: jquery get name value method 
Javascript :: TypeError: path must be absolute or specify root to res.sendFile 
Javascript :: node http2 post 
Javascript :: bootstrap carousel dynamic height jquery 
Javascript :: change text based on dropdown selection javascript 
Javascript :: localhost:3000 ad is not working with outlook angular 8 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =