react-router-v4

React history.push() not rendering new component

柔情痞子 提交于 2020-08-02 07:06:13
问题 Good day, everybody! I have a React.js project with a simple sign in function. After the user is authorized, I call history.push method which changes the link in the address bar but does not render the new component. (I use BrowserRouter) My index.js component: ReactDOM.render( <Provider store={createStore(mainReducer, applyMiddleware(thunk))}> <BrowserRouter> <Main /> </BrowserRouter> </Provider>, document.getElementById('root') ); My Main.js component: const Main = (props) => { return (

How to use React's BrowserRouter on client and Java REST API (Spring Boot) on the server?

强颜欢笑 提交于 2020-07-18 11:43:17
问题 I want to use React on the client and Java Spring Boot on the server for REST API, both client and server are packaged together so they are hosted on the same application server. I can already query the server APIs via the /api path. But (how) can I use the BrowserRouter of react-router-dom (Router v4) on the client instead of the HashRouter ? I don't know Spring Boot well, but I guess I could check on the server if the route does not match /api , then I would return the index.html with all

React Router Dom Protected Route Always Redirects to Login during refresh page

痞子三分冷 提交于 2020-06-29 03:51:22
问题 I’m building a full stack react application. I have implement React router v4 protected route. everything going good but the problem is that after user login on refresh link it redirect to login page. Here is the auth.js code: it is use for check authentication during login and logout time. class Auth { constructor() { this.authenticated = false; } login(cb) { this.authenticated = true; cb(); console.log("login status"+this.authenticated) } logout(cb) { this.authenticated = false; cb(); }

How to hide Nav bar in some react components

≡放荡痞女 提交于 2020-06-27 11:37:22
问题 I am trying to make a login flow using react. Routes are working as expected. But when I try to introduce nav bar, it is visible on all routes. I want to show nav bar only on selected components (only on profile and home route). Any suggestions would be appreciated. This is the Routes.js: export default class Routes extends Component { render() { return ( <Switch> <Route exact path='/*/home' component={Home} /> <Route exact path='/*/login' component={Login} /> <Route exact path='/*/profile'