hookrouter
hookrouter copied to clipboard
Handle trailing slashes?
Assuming the following routes:
const routes = {
'/docs': () =>
<h1>My Docs</h1>
,
}
If the user visits /docs/
in their browser, the route does not match.
As a workaround I have to do useRedirect('/docs/', '/docs')
Hi @Paratron , I am new to Github contribution, I want to kick off with this for the first one, I found that updating regex can solve it.
new RegExp(`${inRoute.substr(0, 1) === '*' ? '' : '^'}${inRoute.replace(/:[a-zA-Z]+/g, '([^/]+)').replace(/\*/g, '')}${inRoute.substr(-1,) === '*' ? '/*' : '/*$'}`)
This can match /docs
and /docs/
too.
What do you think? If it's ok, I am willing to create a PR.
I would be interested in as well. Any chance get get this into one of the next releases?