-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVocabRouteHandler.js
More file actions
24 lines (20 loc) · 798 Bytes
/
VocabRouteHandler.js
File metadata and controls
24 lines (20 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { useEffect } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { useSidePanel } from '../context/SidePanelContext';
import { vocabulary } from '../data/vocabulary';
const VocabRouteHandler = () => {
const { term } = useParams();
const navigate = useNavigate();
const { openSidePanel } = useSidePanel();
useEffect(() => {
if (term && vocabulary[term]) {
const def = vocabulary[term];
openSidePanel(def.title, def.content);
}
// Redirect to home so the background isn't empty/404.
// In a real app, we might want to stay on the "previous" page, but we don't know what that is on hard refresh.
navigate('/', { replace: true });
}, [term, navigate, openSidePanel]);
return null;
};
export default VocabRouteHandler;