Create React Nested Router component

Programming ReactJS Technology

Today, We want to share with you Create React Nested Router component.In this post we will show you Nested routes with react router v4 / v5, hear for Simple Nested Routes with Layouts in React Router we will give you demo and example for implement.In this post, we will learn about Create Nested Tab Routes with Dynamic Paths with React-Router with an example.

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

Snippet Contents

Create React Nested Router component

There are the Following The simple About Create React Nested Router component Full Information With Example and source code.

As I will cover this Post with live Working example to develop Nested Routes – React router beginners guide, so the Understanding Nested Routing in React Directory structures for this example is following below.

React Rendering Our List

./src/containers/ProductsPage.js

import React from 'react';
import { connect } from 'react-redux';
import ProductsList from '../components/ProductsList';

const ProductsPage = ({ products }) => 
  <div>
    <ProductsList products={products} />
  </div>;

const mapStateToProps = (state) => {
  return {
    products: state.products
  };
}

export default connect(mapStateToProps)(ProductsPage);

./src/components/ProductsList.js

import React from 'react';
import { Link } from 'react-router-dom';

const ProductsList = ({ products }) => {
  const renderProducts = products.map(product => 
    <Link key={product.id} to={`/products/${product.id}`}>{product.title}</Link>
  );

  return (
    <div>
      {renderProducts}
    </div>
  );
};

export default ProductsList;

./src/containers/ProductsShow.js

import React from 'react';

const ProductsShow = props => {

  return (
    <div>
      <h3>Products Show Component!</h3>
    </div>
  );
}

export default ProductsShow;

.src/containers/ProductsPage.js

import React from 'react';
import { Route } from 'react-router-dom';
import { connect } from 'react-redux';
import ProductsList from '../components/ProductsList';
import ProductShow from './ProductShow';

const ProductsPage = ({ match, products }) => 
  <div>
    <ProductsList products={products} />
    <Route path={`${match.url}/:productId`} component={ProductShow}/>
    <Route exact path={match.url} render={() => (
      <h3>Please select a Product from the list.</h3>
    )}/>
  </div>;

const mapStateToProps = (state) => {
  return {
    products: state.products
  };
}

export default connect(mapStateToProps)(ProductsPage);

./src/components/ProductsList.js

import React from 'react';
import { Link } from 'react-router-dom';

const ProductsList = ({ products }) => {
  const renderProducts = products.map(product => 
    <Link to={`/products/${product.id}`}>{product.title}</Link>
  );

  return (
    <div>
      {renderProducts}
    </div>
  );
};

export default ProductsList;

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Create React Nested Router component.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Simple Vue 2.0 Select All Checkbox
  2.   codeigniter 3 Multiple File Drag and Drop Upload
  3.   Nested routing in React Router
  4.   PHP MySQLi Database Connection
  5.   PHP Uploading Multiple Files to Amazon S3 Server
  6.   How to Select VueJs Check All Uncheck All Checkboxes
  7.   Laravel 6 Join multiple tables Eloquent Examples
  8.   jQuery Multiple Email Address Validation in one text box
  9.   Simple Vuejs Currency Converter Example
  10.   ng-options to Set Default Value using Angular Example

Leave a Reply

Your email address will not be published. Required fields are marked *