remix-run / history

Manage session history with JavaScript
MIT License
8.29k stars 959 forks source link

Making history work with custom schemes #311

Closed victorporof closed 8 years ago

victorporof commented 8 years ago

Hi!

I'm trying to get react-router to work in an environment with custom url schemes. Understandably, this isn't supported by this library yet afaict, and it seems that the assumption that standard http/https schemes are used is deeply ingrained in the code.

Custom schemes are a bit interesting because certain assumptions about where our app is located and how navigation happens are not valid anymore. E.g., with a custom app scheme, navigation between different views can happen between app://foo and app://bar/baz, however standard URI parsing would make foo and bar hostnames, whereas it would be pragmatically more correct to consider them paths along with baz.

The discussion started here https://github.com/reactjs/react-router/issues/3531 and originates from an effort to use react-router in an electron app: https://github.com/mozilla/tofino/pull/609

taion commented 8 years ago

I think this is too specific to add to this library as-is, since the use case is very restricted. I was recommending instead that you implement this history in userspace.

Take a look at the implementation of createBrowserHistory (maybe more the v2 version, since React Router still points at history v2 for the moment) – you might need to duplicate a bit of code, but it shouldn't be too hard to set this up.

timdorr commented 8 years ago

@taion I disagree. As electron has grown in popularity, it has become a popular platform for building apps, including React apps needing a router, and therefore a history implementation. We're only talking about a small 4 line function being expending to parse other types of paths. Protocol flexibility is good for the library.

@victorporof Making this work will involve a history enhancer that replaces listen, push/replace, createPath/createHref. So, basically the whole damn thing. Instead, I'd just fork the project and fix PathUtils.extractPath.

taion commented 8 years ago

In general you don't care what the URL is in an Electron app. I can guess why it'd matter in the context of Tofino, but that's a fairly specific use case.

mjackson commented 8 years ago

FWIW this shouldn't be an issue in 3.0. We allow protocol-relative URLs, which should also match custom schemes.

@victorporof If you'd like to provide a test case for custom schemes here, that would be great. Thanks :)