Static routes do not react to two pages of different content

0

The situation is as follows, when creating an app with the react + webpack I have an html file, it is an index.html that loads a bundle.js (default webpack) to be displayed in the browser, but my app needs has the following structure, it has a screen that contains a form that can be filled in a / form route and a login screen to manage content entered by users in / login in> being that in a moment the login will have some component to go to the form and vice versa, and I already tried to use the react-router-dom to do this, but it does not seem to work in this question

    
asked by anonymous 05.07.2017 / 04:17

1 answer

0

If I understand correctly, your problem is only in the configuration of the react-router-dom.

index.jsx

import { render } from 'react-dom';
import Route from './route';

const rootEl = document.getElementById('app');

render(
    <div>
        <Route />
    </div>,
rootEl);

Here you can import your route setup.

route.jsx

import React from 'react';
import { Switch, Route, Redirect } from 'react-router-dom';
import App from './components/App';
import Login from './components/login/Login';
import Signup from './components/signup/Signup';

export default () => (
  <Switch>
    <Route path="/signup" render={props => <Signup {...props} />} />
    <Route path="/" render={props => <App {...props} />} />
    <Route path="/login" render={props => <Login {...props} />} />
  </Switch>
);

In this component I select the route for my App, Login or Signup component.

Within my App (or Signup, Login, and any other component you add on this route) I can have more routes, one that points to / form:

App.jsx

const App = () => (
  <div>
    <Switch>
      <Route exact path="/" component={Dashboard} />
      <Route path="/form" component={ComponentForm} />
    </Switch>
  </div>

And so you get to the component Form by your App component.

This link has a good tutorial on this.

    
15.08.2017 / 20:46