Don't need useLocation when in compose pop-out

This commit is contained in:
Lim Chee Aun 2023-01-21 13:21:57 +08:00
parent 37fc65b47a
commit e0d50168fd

View file

@ -11,7 +11,10 @@ import states from '../utils/states';
*/
const Link = (props) => {
const routerLocation = useLocation();
let routerLocation;
try {
routerLocation = useLocation();
} catch (e) {}
let hash = (location.hash || '').replace(/^#/, '').trim();
if (hash === '') hash = '/';
const isActive = hash === props.to;
@ -21,7 +24,7 @@ const Link = (props) => {
{...props}
class={`${props.class || ''} ${isActive ? 'is-active' : ''}`}
onClick={() => {
states.prevLocation = routerLocation;
if (routerLocation) states.prevLocation = routerLocation;
}}
/>
);