react-router-dom

React Router - How to redirect user if logged in?

人盡茶涼 提交于 2021-01-28 07:40:30
问题 I'm using react-router-dom to manage my routes: const Routes = () => { return ( <BrowserRouter> <div> <Route path="/" component={Navbar} /> <Switch> <Route exact path="/" component={Main} /> <Route path="/signin" component={SignIn} /> <Route path="/signup" component={SignUp} /> <PrivateRoute path="/dashboard" component={DashboardRoutes} /> <Route path="*" component={() => <h1>Page not found</h1>} /> </Switch> </div> <div> <Route path="/" component={Footer} /> </div> </BrowserRouter> ); }; I

React Router - How to redirect user if logged in?

倖福魔咒の 提交于 2021-01-28 07:21:00
问题 I'm using react-router-dom to manage my routes: const Routes = () => { return ( <BrowserRouter> <div> <Route path="/" component={Navbar} /> <Switch> <Route exact path="/" component={Main} /> <Route path="/signin" component={SignIn} /> <Route path="/signup" component={SignUp} /> <PrivateRoute path="/dashboard" component={DashboardRoutes} /> <Route path="*" component={() => <h1>Page not found</h1>} /> </Switch> </div> <div> <Route path="/" component={Footer} /> </div> </BrowserRouter> ); }; I

How to pass params into link using React router v6?

两盒软妹~` 提交于 2021-01-28 05:12:34
问题 This is my main section class where all routes to the links is kept export default class Section extends React.Component { render() { return ( <div style={{backgroundColor:"white"}}> <Routes> <Route path="/" element={<Home/>} /> <Route path="/discover" element={<Discover/>} /> <Route path="/shop/makeup" element={<Makeup/>} /> <Route path="/home/:id" element={<DetailsPage/>} /> </Routes> </div> )}} This is my card page which is getting data from the context. import React from 'react'; import

React router base code-splitting (get first chunk and then get other chunks async in background)

不羁的心 提交于 2021-01-27 19:56:08
问题 I am using create-react-app. I want to react-router base code-splitting but I want to get the first chunk which user open in browser and then get other chunks asynchronously in the background Routes const HomeModule = React.lazy(() => import('./modules/ft_home_module/src/main')); const AuthModule = React.lazy(() => import('./modules/ft_auth_module/src/main')); const ProfileModule = React.lazy(() => import('./modules/ft_profile_module/src/main')); const MerchantModule = React.lazy(() => import

PhpStorm can't resolve package import even though it exists (react-router-dom)

烂漫一生 提交于 2021-01-27 16:10:17
问题 I am using React (16.12.0) with PhpStorm (2019.3.1). The package I am importing is react-router-dom (5.1.2) I will write the following import: import { NavLink, Switch } from "react-router-dom"; Both packages are imported properly by webpack/babel and the page renders properly when I use both Switch and NavLink. However purely from the IDE-perspective, I get a warning about Switch: Cannot resolve symbol 'Switch' It is weird because it is obviously there, and I checked in /node_modules/react

PhpStorm can't resolve package import even though it exists (react-router-dom)

橙三吉。 提交于 2021-01-27 16:02:23
问题 I am using React (16.12.0) with PhpStorm (2019.3.1). The package I am importing is react-router-dom (5.1.2) I will write the following import: import { NavLink, Switch } from "react-router-dom"; Both packages are imported properly by webpack/babel and the page renders properly when I use both Switch and NavLink. However purely from the IDE-perspective, I get a warning about Switch: Cannot resolve symbol 'Switch' It is weird because it is obviously there, and I checked in /node_modules/react

Why does useParams during test return undefined in test env with wrapper?

笑着哭i 提交于 2021-01-27 06:41:53
问题 I have seen this in 2 different code bases now and am stumped because it works fine in the actual browser but not the tests: if a component uses the useParams hook, the hook throws an error in the test: Error: Uncaught [TypeError: Cannot destructure property accountId of 'undefined' or 'null'.] I am using React Functional Component, React Testing Library and React-Router: // component: const Overview: FC = () => { const location = useLocation(); console.log(location) // see below const {

Symfony 4 how to setup SPA ( single page app ) with React?

烂漫一生 提交于 2021-01-21 05:55:05
问题 I've not been able to have Symfony 4 work properly in a SPA setup. Specifically, while I navigate using React-router links everything works as it should. But if I try accessing any of the routes ( except home ) directly, Symfony intercepts it and, of course, throws an error for route not found. The alternative of placing Symfony in a sub-domain and using it only as an API is not viable, as I need all the user and session management tools provided by the framework. Of course I will need

react.js with webpack Resource blocked due to MIME type mismatch, when accessing an url params with react router

谁说胖子不能爱 提交于 2021-01-07 07:46:25
问题 When I try to access the URL like for example localhost:8080/edit/12 I get an error on the console and I can't access the id from it, is it the problem in the versions used on the package.json or in the webpack config file? Component EditExpensePage: import React from "react"; const EditExpensePage = (props) => { return ( <div>This is from EditExpensePage component at {props.match.params.id}</div> ); }; export default EditExpensePage; Component router AppRouter: import React from "react";

React js Router changes url but not loading page

孤街醉人 提交于 2020-12-31 06:49:10
问题 I have a big problem, I'm using react BrowserRouter, Link and Switch to manage my website routing, my problem is that when I click on a link it changes on url but not in view, however when I refresh the page it works. This is my Index.js page : import React from 'react'; import ReactDOM from 'react-dom'; import { BrowserRouter, Route, Switch } from 'react-router-dom'; import Home from './Home'; import Header from './Header'; import Footer from './Footer'; import Resume from './Resume'; import