2

I'm trying to display CollectionPage Component from ShopPage component as a nested route that receives collectionId as a param but I get an empty page. These are my components.

Shop Page :

import React from 'react';
import CollectionsOverview from '../../components/collections-overview/collections-overview.component';
import { Route } from 'react-router-dom'
import CollectionPage from '../collection/collection.component';

const ShopPage = ({ match }) => (
    <div className='shop-page'>
        < Route exact path={`${match.path}`} component={CollectionsOverview} />
        <Route exact path={`${match.path}/collectionId`} component={CollectionPage} />
    </div>
)

export default ShopPage;

CollectionPage Component :

import React from 'react';
import CollectionItem from '../../components/collection-item/collection-item.component';
import './collection.styles.scss';


const CollectionPage=({match})=>{
    console.log(match);
    return(
    <div className="collection-page">
        <h2>Collection Page</h2>
    </div>
)}

export default CollectionPage;
Amine
  • 57
  • 7

1 Answers1

2

It seems that collectionId is a parameter which should be prefixed by : like :

 <Route exact path={`${match.path}/:collectionId`} component={CollectionPage} />

and remove exact from <Route path="/shop" component={ShopPage} /> in App.tsx check this

Boussadjra Brahim
  • 82,684
  • 19
  • 144
  • 164