#useMatches returning undefined

1 messages · Page 1 of 1 (latest)

rancid wharf
#

I have this error only on lower version of Safari (Safari 14.1). My code look like this:

export const useCurrentRoute = () => useMatches().at(-1)?.pathname;

I'm not sure why useMatches() returns an undefined value here

mellow veldt
#

You'll need to use the older matches[matches.length - 1] trick instead if you want to support that

#

or include a polyfill

rancid wharf
#

Ah yes! I totally forgot about that!