2017-05-03 6 views

Antwort

0

Leider glaube ich nicht, dass dies mit router.isActive möglich ist, da es Pfadparameter nicht unterstützt (d. H. router.isActive('/animals/edit/:number')).

Als Alternative mit React Router v4 ist matchPath Sie tun können:

import { matchPath } from 'react-router' 

const match = matchPath(currentPath, { 
    path: '/animals/edit(/:number)', 
    exact: true, 
    strict: false 
}) 
0

ich hatte das gleiche Problem. Lösen Sie es, indem Sie die Route mit router.getCurrentLocation().pathname übereinstimmen.

In Ihrem Beispiel Folgendes sollte es tun:

const parentPathname = '/animals/edit'; 
const currentPathname = router.getCurrentLocation().pathname; 
const isActive = currentPathname.indexOf(parentPathname) !== -1; 
Verwandte Themen