score:0

import { useLocation } from "react-router-dom"

// 
const { pathname } = useLocation();

const Component = () => {

    return (
        {pathname === '/SavedRecipes' ? (
        ....
        )}
    );
}

score:0

  const pathnameIsSavedRecipes =  window.location.pathname === '/SavedRecipes'

  <Button
    onClick={() => setSearchQuery("")}
    color="inherit"
    to={pathnameIsSavedRecipes ? "/" : "/SavedRecipes"}
    component={RouterLink}
  >
    {pathnameIsSavedRecipes ? "Search" :  "Saved Recipes"}
    {!pathnameIsSavedRecipes && <BookmarkBorderIcon />}
  </Button>

score:0

import { useHistory ,useLocation } from 'react-router-dom';
const location = useLocation()
location.pathname

const history = useHistory()
history.location.pathname

Related Query

More Query from same tag