Nested routes with react router v4 / v5

后端 未结 11 1881
广开言路
广开言路 2020-11-22 12:34

I am currently struggling with nesting routes using react router v4.

The closest example was the route config in the React-Router v4 Documentation.

I want t

11条回答
  •  孤街浪徒
    2020-11-22 13:11

    You can try something like Routes.js

    import React, { Component } from 'react'
    import { BrowserRouter as Router, Route } from 'react-router-dom';
    import FrontPage from './FrontPage';
    import Dashboard from './Dashboard';
    import AboutPage from './AboutPage';
    import Backend from './Backend';
    import Homepage from './Homepage';
    import UserPage from './UserPage';
    class Routes extends Component {
        render() {
            return (
                
    ) } } export default Routes

    App.js

    import React, { Component } from 'react';
    import logo from './logo.svg';
    import './App.css';
    import { BrowserRouter as Router, Route } from 'react-router-dom'
    import Routes from './Routes';
    
    class App extends Component {
      render() {
        return (
          
    ); } } export default App;

    I think you can achieve the same from here also.

提交回复
热议问题