Router: Feature request: expose isCurrent & isPartiallyCurrent as public API helpers

Created on 2 Aug 2018  路  3Comments  路  Source: reach/router

First of all, thanks for the lib!

Context

I'm making a collapsible navigation menu. The menu has groups with inner links.
Each group is collapsible, but should be forced open if any of the inner links is active.

With the current API I do not see a proper solution. To solve this I see two solutions.

1) expand the Match component to accept multiple paths

  <Match path={['/one','/two/three']}>({match}) => {....})</Match>

2) expose isCurrent and isPartiallyCurrent as public API helpers

https://github.com/reach/router/blob/054187e17795c5c2df289109456ce42c48f49343/src/index.js#L377-L379 should be public

Would it be possible to add this to the library?

enhancement

Most helpful comment

@ricardobrandao, true, that's giving the info on the child level. What I need is to have a check for the parent level, to see if any of it's children is active. I do not want to use the routing hierarchy, but just match against a set of paths if any of these paths isCurrent

All 3 comments

Link components already have a getProps property that receives those properties. Please refer to the example in the documentation.

@ricardobrandao, true, that's giving the info on the child level. What I need is to have a check for the parent level, to see if any of it's children is active. I do not want to use the routing hierarchy, but just match against a set of paths if any of these paths isCurrent

This would also be useful for Linaria or styled components:

import { styled } from 'linaria/react'
import { Link, LinkProps } from '@reach/router'
import React, { FC } from 'react'

const RedLinkIfCurrent: React.FC<LinkProps<any>>(Link)`
  color: ${props => props.isCurrent ? 'red' : 'black' };
`
//                            ^-------- doesn't work
Was this page helpful?
0 / 5 - 0 ratings

Related issues

MarioKrstevski picture MarioKrstevski  路  3Comments

kbrgl picture kbrgl  路  4Comments

maieonbrix picture maieonbrix  路  4Comments

ryanflorence picture ryanflorence  路  4Comments

thupi picture thupi  路  4Comments