I changed the parameter in a link (Eg. localhost:3000/home/id, id is the parameter here), but now I want the whole page not to reload, only the parameter where the change has happened should reload, and the rest of the things should stay intact. Is there any way to do this in React?
I tried using optional path parameters, but on changing the link every time it got refreshed. I was not able to get any powerful resources for that.
PARENT CODE
import { AnimatePresence } from 'framer-motion';
import Manufacturing from './Manufacturing';
function App() {
const location = useLocation();
return (
<AnimatePresence>
<Routes location={location} key={location.pathname}>
<Route path="/manufacturing/:id?" element={<Manufacturing />} />
</Routes>
</AnimatePresence>
)
}
export default App
MANUFACTURING
import 3D_Model
function Manufacturing() {
const handleClick = (id) => {
console.log(document.getElementbyId(id));
}
useEffect(() =>{
if(id != null) {
handleClick(id);
}
}, [id]);
return (
// Load my 3D_Model
3D_Model
<button id="1" onClick={handleClick}> First Button </button>
<button id="2" onClick={handleClick}> Second Button </button>
<button id="3" onClick={handleClick}> Third Button </button>
)
}
export default Manufacturing
Now, in this piece of code, if I change the URL from localhost:3000/manufacturing/1 to localhost:3000/manufacturing/2, I want the 3D model not to reload, and only the useEffect should get triggered. Any way to make this work?