React - conditional view based on URL

0 votes
38 views
added Jan 8 in React by lcjr First Warrant Officer (11,830 points)
import React from 'react';
import { useLocation } from 'react-router-dom'; // Assuming you are using React Router

const DetailTitle = () => {
  const { pathname } = useLocation();

  return (
    <div>
      {pathname === '/pageA && <h1>This is page A detail title</h1>}
      {pathname === '/pageB' && <h1>This is page B detail title</h1>}
    </div>
  );
};

export default DetailTitle;

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...