20,572 questions
0
votes
2
answers
50
views
How to display <NavLink> components outside MemoryRouter in React Router? [duplicate]
How to display <NavLink> components inside the Footer? I cannot place the Footer inside RouterProvider. The Footer component should be displayed on every page.
function App() {
const router = ...
Advice
1
vote
2
replies
67
views
React Router v7 SPA mode: How to use strict CSP?
I'm migrating an app from React Router v6 + Webpack to React Router v7 (SPA mode) + Vite and I'm having issues with setting a strict Content Security Policy.
In RR6 I had a normal index.html and ...
1
vote
1
answer
56
views
How does it work (internally) when returning Navigate component in React Router v7?
I'm trying to implement a redirect based on a property passed to a component nested deep within my route hierarchy. Right now I know 2 options how to do it.
const MyComponent = ({ variable }: { ...
Tooling
0
votes
3
replies
60
views
React router dom
I want to use react-router-rom and can we still use react-router-dom V5 in today's date? since it support custom route components, while react-router-dom V6+ has strict rules to use Route & Routes....
0
votes
0
answers
19
views
React redirection using auth [duplicate]
I have a app where I am using JWT authentication. When I enter the details and click on the register button, the backend API correctly returns the token but in my console the token stays only for some ...
2
votes
1
answer
84
views
Reuse the same user routes under '/' (UserLayout) and '/admin' (AdminLayout) without duplication
I need to define user pages (Home, Cows, Reports, …) once and make them accessible to AppUser + Admin under "/" with UserLayout, and also accessible to Admin under "/admin/user/*" ...
3
votes
1
answer
80
views
How do I pass data inside fetch function from createBrowserRouter to load content before page has loaded
I'm using react-persist in my application. When I click to add a product to my basket and then want to navigate to my basket page, how do I pass the basket data to the fetch function in the loader ...
1
vote
1
answer
246
views
React Router With Browser Extension Popup Window?
I'm trying to incorporate React Router into my Firefox browser extension to be able to display different pages in the extension's popup window. However, I keep getting the warning, You should call ...
3
votes
1
answer
104
views
React Router Nested Routes
I'm having issues configuring react-router-dom with nested routes loaded by sub-modules.
In my application I need to dynamically load modules that have their own nested routes. One of the requirement ...
0
votes
0
answers
70
views
navigate() in ReactJS shows blank page after routing
The reactJS client has left pane for menu and right for content. The react-route-dom 7.6.3 is used to create route in App.js as below:
const router = createBrowserRouter([
{
path: "/...
4
votes
1
answer
283
views
API route in react-router v7 SPA always throws an error
I currently have a React Router v7 application running in SPA mode. I wanted to make an API route that uses a clientAction to submit data to an endpoint. If I use the useSubmit hook, I can ...
-3
votes
1
answer
233
views
How do I use redux-persist and rtk with React Router v7 Framework (without SSR)? [closed]
I'm trying to migrate an existing React/Vite app (currently using React Router v7, along with redux, rtk-query, and redux-persist) to use React Router v7 in Framework mode. I'm hitting an error when ...
0
votes
1
answer
123
views
Styles not being applied to page using spa mode in build
I have problem with my React app, using Vite and React-Router v7, in framework mode, ssr: false.
When using dev mode, all styles are being applied correctly (I'm using moduled SCSS, and one global app....
2
votes
0
answers
137
views
Preventing race condition between history navigation and route replacement
I'm using React Router v7 with BrowserRouter and need to navigate back multiple steps in browser history, then replace the resulting route atomically. My current approach causes a race condition where ...
1
vote
1
answer
613
views
How to redirect in React Router 7 in Framework mode to another route
I just want to redirect one path to another.
If I have something like this in my routes.ts:
export default [
index("Home.tsx"),
route("/about", "About.tsx"),
] ...
2
votes
3
answers
232
views
Is there a way to set a path param in react-router?
In react-router, there is a hook to retrieve path parameters, for example "/users/:id" where the code can access the id value.
In this example :id is a slug for a path parameter, and within ...
2
votes
1
answer
81
views
React Router renders wrong component for the grandchildren. @react-router/dev
Routes.ts
import {
type RouteConfig,
index,
route,
layout
} from "@react-router/dev/routes";
export default [
layout("layouts/main_layout.tsx", [
route("...
-3
votes
2
answers
277
views
How to make a nested route the site index route in React-Router v7
Here is an example routes.tsx file for my React-Router v7 application
import {
type RouteConfig,
index,
prefix,
route
} from "@react-router/dev/routes";
export default [
index (&...
-3
votes
1
answer
101
views
Configure individual routes in React Router for URL paths that start with '.' and '@'
Is it possible to configure routes in React Router that match URLs starting with . and @?
I have this in routes.ts:
export default [
route('.:param', "routes/dotroute.tsx"),
route('@:...
0
votes
0
answers
23
views
How to restrict access to a page in React based on Supabase user login? [duplicate]
Body
I'm building a kids' poem and story website using React and Supabase. I have successfully implemented login/signup using Supabase auth.
What I'm trying to do:
I want to restrict access to certain ...
-3
votes
1
answer
100
views
Why I'm getting error every time i try to access the protected route instead of redirect to /login? [closed]
I'm implementing protection route in my vanlife practice project and its not redirecting me it keep giving me this error when i try to access protected route
I'm supposed to get redirected to /login ...
-1
votes
1
answer
555
views
Test failure after upgrading to React Router v7.6.2
I am experiencing an issue after upgrading to React-Router version 7.6.2. I was able to replicate the failure: StackBlitz. Note that this test passed when I had v6 of React-Router-DOM.
The problem ...
0
votes
1
answer
83
views
Multiple routes for one component
I have a React router version 7^, app with in framework mode (It was a Remix 2 app that I upgraded to React router). Now I'd like to have a page with a loader and an action to be on two different ...
3
votes
1
answer
116
views
How to get React-Router Route object properties?
From docs: https://reactrouter.com/6.30.1/route/route
Type declaration
interface RouteObject {
path?: string;
index?: boolean;
children?: RouteObject[];
caseSensitive?: boolean;
id?: string;...
3
votes
1
answer
2k
views
Vite and React Router base path struggles
I can't figure out how Vite and React Router (v7 Framework) are supposed to work together with a base path.
In my vite.config.js I'm using base: '/my-app/'. If I use /my-app instead, then the build ...
0
votes
0
answers
35
views
Protected route briefly renders before redirect in React Router [duplicate]
I'm using React Router to implement protected routes in my application. Everything works as expected in terms of redirecting unauthorized users — they get sent to the login or access-denied page ...
0
votes
2
answers
140
views
Issue with navigate in React Router v7.5.3: TypeError: Cannot read properties of undefined (reading 'toUpperCase')
I've been working on a React project where I use react-router for navigation. My code works perfectly with react-router v7.4.0, but after upgrading to v7.5.3, I'm encountering a TypeError: Cannot read ...
2
votes
1
answer
779
views
How to set basename for react-router v7 framework mode?
I have created a React-Router framework mode app like this:
npx create-react-router@latest my-react-router-app
The version of React-Router is:
"react-router": "^7.5.1"
In routes....
3
votes
2
answers
171
views
I cannot figure out why ProtectedRoute wont re-render after updating useState
I would like the ProtectedRoute to call server and get a response that indicates whether the user is logged in or not, on every render of a page that it protects. The server is sent a session cookie ...
0
votes
0
answers
15
views
React router navigate() after state change doesn't navigate [duplicate]
I have a React App that uses the username throughout the app so it is declared in App.tsx
let [username, setUsername] = useState<string>("");
and I pass that as a property to all my ...
1
vote
1
answer
56
views
How do I stream non-critical data?
I have a CSR app with the following route definitions:
const router = createBrowserRouter([
{
path: '/app/',
element: <NavBar />,
loader: navBarLoader,
children: [
{
...
0
votes
0
answers
22
views
Route Transition Flickering in React Router Framework v7 (Private Routing) [duplicate]
I'm currently developing a project utilizing React Router v7 framework where I need to implement protected routes. While I've successfully implemented the protection mechanism, I'm encountering an ...
2
votes
1
answer
627
views
How do you configure and set up folders to support nested routes in React Router V7
I'm using React Router V7 in framework mode.
The goal is to put all related pages in a common folder, so that routes file doesn't extend linearly. We have a few namespaces: public, organization, ...
-1
votes
1
answer
220
views
How to pass props to Layout component?
I have a heading in Layout and I want to pass props to it. So I can start my <main> element.
Here is my Layout.tsx
<>
<h1>{title}</h1>
<main>
<Outlet /> {/* ...
1
vote
3
answers
85
views
MERN Stack -TodoAPP - Nothing display when adding Route
I was learning and practising tutorial on mern stack, by watching a video on youtube but nothing is displayed since I have added the Routes. White page. Is there anyone who get an idea what is wrong.
...
0
votes
1
answer
62
views
How come visiting child component loses functionality?
I have an app that has a 3 JSX files:
one for controlling states
import React from "react";
import CreateRisk from "./CreateRisk";
import TablePage from "./TablePage";
...
1
vote
1
answer
49
views
Redirect when path parameter is not provided in react-router-dom
I have the following routes defined in react-router-dom
<Route id='editor' path='editor' >
<Route index element={<Editor />} />
<Route id='edit' path='edit/:documentId' ...
1
vote
1
answer
74
views
Form disable the overflow
I try to implement an overflow in Form react-router, that's work in a classic <div></div> but when I use <Form></Form> my overflow doesn't work. I don't find any topic who talk ...
-2
votes
1
answer
95
views
Can anyone render react-router-dom components with react-testing-library?
After a lot of trial and error I cannot get RTL to render any components from react-router-dom. I am using [email protected], @testing-library/[email protected], @testing-library/[email protected], react-router-...
-2
votes
2
answers
77
views
Is there a way to intercept page beforeuonload with history.listen in React-router v.7? [duplicate]
The goal is to save a form before user leaves a page.
Before we switched to react-router v.7 from v.5 we used history package, which is compatible with react-router only up to v.6.
The code we used in ...
1
vote
1
answer
113
views
React Routes Question about routes with same path and components
In my React code I have these 2 files in App.js and Users.js. By using Routes just for fun and experimenting to render some random text, I have 3 routes that have the same path and components but ...
-4
votes
1
answer
241
views
createMemoryRouter throws TypeError: Cannot destructure property 'basename' of 'React10.useContext(...)' as it is null [closed]
Using createMemoryRouter to create router to render doesn't work. It renders and error page.
import { vi, describe, it, expect } from 'vitest'
import { render } from '@testing-library/react'
import { ...
1
vote
1
answer
533
views
Fetcher triggers a full page reload with React Router v7 (framework)
I use React Router v7 as a framework. I don't understand why posting data with a fetcher triggers a full page reload. I might be mistaken but to my understanding, it should just post the data, reload ...
-1
votes
1
answer
408
views
How to integrate MUI Toolpad's PageContainer with a custom Sidebar?
Material UI has a component called PageContainer which provides a title and breadcrumb navigation as shown here:
https://mui.com/toolpad/core/react-page-container/
I want to navigate to the same place ...
1
vote
2
answers
285
views
I'm using React Router v7.20 and getting this error in my Account.jsx component [closed]
The error happens when I refresh the page or navigate between "/account", "/account/bookings", and "/account/places".
import React, { useContext } from 'react';
import { ...
0
votes
1
answer
446
views
React Router v7 splats paths migration issue
I'm trying to create a scenario for migration of React-Router from version 6 to version 7.
I have followed the migration steps of the documentation but the routing is not working.
I'm stuck and can't ...
-1
votes
3
answers
75
views
Passing and getting params in React routes using navigate() [duplicate]
I am currently stuck in passing paramters to another route using navigate() function.
MainPage.js:
After an API call the value for the below used objects will be obtained
const navigate = useNavigate(...
2
votes
1
answer
95
views
MUI Breadcrumb Integration with react-router
I'm trying to get Material-UI Breadcrumbs to work with React-Router. There is an example on the MUI site:
import * as React from 'react';
import Box from '@mui/material/Box';
import List from '@mui/...
-1
votes
1
answer
70
views
How can I prevent my list component from remounting when using modal routes with HashRouter in React Router v5?
I’m adjusting some functionality for a React app (using React 16.13.1) with React Router v5 and HashRouter. My app displays a list of coupons in a table (using AgGrid) within a component (named ...
2
votes
1
answer
1k
views
React Router 7 accessing loaderData in meta function
I tried reading the React Router 7 documentation, but can't seem to find a solution to my issue.
So in my React Router 7 Node.js/Express app, I have a loader function for the client, to fetch location ...