Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Error: [ProtectedRoute] is not a component

<Route path='/profile' element={<PrivateRoute/>}>
  <Route path='/profile' element={<Home/>}/> // inner/nested route
</Route>


// Your PrivateRoute Component should look like this
import React from 'react';
import { Navigate, Outlet } from 'react-router-dom';
import { auth } from '*somewhere*';

const PrivateRoute = () => {
  const { userLoggedIn } = auth();
  if (userLoggedIn) {
    return <Outlet />; // i.e continue to the inner/nested route
  } else {
    return <Navigate to="/login" />;
  }
  
  // same thing as 
  // 'return userLoggedIn ? <Outlet /> : <Navigate to="/login" />;'
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: datepicker get selected date 
Javascript :: javascript add css file 
Javascript :: transition event listener does not work 
Javascript :: get random letter js 
Javascript :: set bg image in react 
Javascript :: remove all spaces from string javascript 
Javascript :: jquery button text 
Javascript :: File is a CommonJS; it may be converted to an ES6 module 
Javascript :: ExpressionChangedAfterItHasBeenCheckedError: 
Javascript :: play music from file js 
Javascript :: check if not checked vanila js 
Javascript :: ng build staging 
Javascript :: importing svg into react 
Javascript :: js alert 
Javascript :: javascript get local storage 
Javascript :: javascript password validation regex test 
Javascript :: local storage size check 
Javascript :: react native android run 
Javascript :: oncheck checkbox javascript 
Javascript :: how to get clicked element class in jquery 
Javascript :: html video autoplay not working 
Javascript :: how to remove menu bar in electron app without removing frame 
Javascript :: how to get back image and front text in react native 
Javascript :: change image on hover js 
Javascript :: wait javascript 
Javascript :: search content in js 
Javascript :: tailwind in react 
Javascript :: jest-environment-jsdom cannot be found 
Javascript :: js minifier api 
Javascript :: chartjs how to disable hover lable 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =