rafgraph / react-router-hash-link

Hash link scroll functionality for React Router
https://react-router-hash-link.rafgraph.dev
MIT License
734 stars 62 forks source link

How about a new props for anchor? #58

Closed vianvio closed 4 years ago

vianvio commented 4 years ago

Currently, I think the reason we can't support hash route is due to these lines

    if (typeof props.to === 'string') {
      hashFragment = props.to
        .split('#')
        .slice(1)
        .join('#');
    } else if (
      typeof props.to === 'object' &&
      typeof props.to.hash === 'string'
    ) {
      hashFragment = props.to.hash.replace('#', '');
    }

If we let the user to set anchor Id, leave a prop such as anchor, and use the string passed in to replace these lines (or leave these lines for default logic also works), then we can support hash routers.

rafgraph commented 4 years ago

Added elementId prop to v2.2.0