score:0
Accepted answer
You can use redirect component from react-router-dom. Here is the documentation page. This is the example usage based upon your situation.
<Route exact path="/view">
{isAdmin ? <AdminPage /> :<Redirect to="/" />}
</Route>
FYI, this is how you import it
import { Redirect } from "react-router-dom";
score:0
store a jwt token and verify the token on backend and see if the token corrsponds to the connected account trying to access url. If token is owned by an admin, return admin page otherwise an error page appear.
Source: stackoverflow.com
Related Query
- How to restrict user from accessing a particular page by typing the url using react and typescript?
- How to restrict user from accessing a page by typing a url using react and typescript?
- How to I prevent user from accessing the page of my react app directly by entering the URL, and redirect them back to login page
- How to prevent the user from accessing other parts of the page until the customized alert box is closed?
- how to remove the /[lang tag] from url using nextjs?
- How to get the user repo from github API using react?
- How to update the url of a page using an input field?
- How to get data from an API only once when the page is loaded using axios.get method?
- How to capture a screenshot of a page using the given url in react
- Calculated row: How to calculate cell value of the particular column based on the values from other rows in the same column using AG Grid?
- How to remove the static/index.html from URL while using React's HashRouter?
- How to scroll to the particular div on button click in a single page application using react-router?
- How could i use the routing in reactjs to redirect from one page after loading to another url
- How can i restrict user from not selecting other file types using input type file with react and typescript?
- How can I decouple the UI from the URL using react-router?
- How can I request the value I get from the user to the backend api using react?
- How do I remove the .html from the end of URL while using SiteGround
- On an cellEditable material-table, how to restrict the user from entering negative number?
- How to show only icon to the particular user when we click on it using reactjs
- How do i send the data from one page to the other using history.push
- How to store the page number in ReactJS (not in state) to construct the GET URL with page number from 1 to 5
- How do you pass data from one view to the other via react-router-dom without using url parameters?
- How to compare current user id with the id from one collection in firebase using React
- How to save the input from user given using html input tag to a array in "state" in React JS
- How to redirect user from login page to another react page if the login was successful?
- How can i show alert to the user when user try to reload the page while file uploading to server from react js?
- How do I redirect user to another page after submit the form using Reactjs?
- How do I use the get request of axios by sending a query from the user and getting the values from the database for that particular query?
- How to redirect to home page from custom 404 page with locale in the url nextjs
- How to remove margin or padding added to the top of page from using bootstrap 4.4.1 when printing using window.print and selecting thinner paper size?
More Query from same tag
- pondjs not recognised after installing
- Serve images using express or send binary data to client
- Having troubles with synchronous rendering
- How do I extend React components already in use?
- There is a way to pass a action via props? To make re-usable components with react-redux
- Why usePrevious returns undefined on first render - react hooks?
- React & Redux-Form - Prevent form from duplicate requests when 1st request hasn't resolved yet
- How to use slice for update an object in array?
- Error with no message for React useNavigate()
- Next.js - Footer / Header loading via API only once, server side
- React query hide error message when setting state object for refetching
- images in Django project only visible when img src='/media/...' not with img src='127.0.0.1/media...'
- How can I pass props to components from different sources?
- TypeScript - invoking React prop with Enzyme
- Adding React-Redux to a React app with React.StrictMode tag
- Render elements from array, which depend on whether the object has certain fields
- react-router v4 and NavLink - routes need to be in a separate component
- What to store in redux state?
- Retrieve image url from database and display in React using Material-UI
- and condition in ternary operator not working
- React error: "could not find the 'store' in the context of ..."
- Child component changing parent component state
- cannot read property 'blur' of undefined?
- Dynamic tooltip using material-table
- How to store multiple values in to objects within an array
- How to add min to redux form field
- How to use UseEffect cleaning on async function for Firebase Login?
- I keep getting [object Object]. when I try to get data from the map function
- Passing components state to query variables inside react-apollo's compose
- Is it a good practice to use getter to render another component inside React component?