score:0

  1. first of all, look into functional components.
  2. a route component expects a component, not logic. handle the actual variable change in that component or elsewhere via react-router's uselocation hook.

what you're attempting to do is to change the state of the variable. cue react's usestate and useeffect hooks (the component needs to be a functional component for hooks to work).

first import the hook:

import { usestate } from 'react';

then, in your case:

const [category, setcategory] = usestate('about') // initial value

and when you need to update it:

setcategory('science') // new value

Related Query

More Query from same tag