larrymyers / react-mini-router

A minimal URL router for React.js
MIT License
282 stars 38 forks source link

navigate() does not respect root configuration value #50

Closed BrandesEric closed 8 years ago

BrandesEric commented 8 years ago

I know that when you configure the router component you can pass a root: "/some/app/root" value. This is excellent. However, navigate() doesn't seem to respect this root value. Would this be something you'd consider adding?

// App
{
  routes: {
    "/": "home",
    "/account": "account"
  }
}

App({root: "/myapp" })  // /myapp is home

navigate("/account") 
// should be /myapp/account
// instead is /account
larrymyers commented 8 years ago

Currently navigate is just a simple wrapper around pushState/hashchange, so it requires the absolute path to navigate to.

An option would be to create a function generator that can take in the root and pass back a navigate function that will always prepend it. This would still require passing it around in the Component context though I believe.

Any thoughts? If you find a solution that works for you I'll happily review a pull request so others can benefit.

BrandesEric commented 8 years ago

Ah yes, I see what you mean...

For now we just handle all navigates in the same component which is aware of the root, so we can avoid context, but I can see where this gets a little tricky. We're quite happy with it as-is, but if any brilliant ideas strike I will certainly submit a PR :)

Thanks!