Как получить параметр запроса

Есть код:

import { useLocation } from 'react-router-dom';

function useQuery() {
    return useLocation().pathname;
}

export { useQuery };

Он возвращает URL подобного вида - /profile/0x738x1608902095352.

Как из этого URL можно извлечь 0x738x1608902095352? Я пытался так:

import { useLocation } from 'react-router-dom';

function useQuery() {
    return useLocation().pathname.match(/(?<=\/)\d+/);
}

export { useQuery };

Но это не дало абсолютно никакого результата.


Ответы (1 шт):

Автор решения: dresser
const input = "/profile/0x738x1608902095352"


const lastSlashIndex = input.lastIndexOf("/")
const lastUrlRes = input.slice(input.lastIndexOf("/"), input.length - 1)

→ Ссылка