When I learned permission routing in react-router, navigate dealt with the jump issue
Navigate component throw an error Unexpected token, expected "," Why display symbol problems?
Detailed errors are shown on the picture above,Could someone help me with this
This is the source code of the error file
import React from 'react';
import { Navigate, useLocation } from 'react-router-dom';
const IsAuth = () => {
if (true) {
return <Navigate to="/login" />;
}
};
export default IsAuth;
i use IsAuth.jsx in index.tsx
import IsAuth from './Login/IsAuth';
const createRoutes = (
(xxxxxx)=>{
...
return (
<IsAuth>
<Routes>
<Routes/>
<IsAuth/>
);
}
)
export default createRoutes;
2
Answers
If you are using react-router-dom then use link instead of navigate.
In other cases you can use this way.
First you take a variable and import useNavigate than you use this variable name. Example: const navigate = useNavigate(). You can try it.
Issues
IsAuth
component is a file with a*.js
file extension so it appears your project has been configured to only expect JSX in*.jsx
|*.tsx
files. rename the file toIsAuth.jsx
.IsAuth
isn’t returning thechildren
prop to render the wrapped components.Solution
IsAuth.jsx
children
for the authenticated pathway.IsAuth.jsx