-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drop the use of createLocation #2680
Conversation
Might as well merge the fixes to the |
@@ -238,6 +231,8 @@ function useRoutes(createHistory) { | |||
'Location "%s" did not match any routes', | |||
location.pathname + location.search + location.hash | |||
) | |||
|
|||
listener() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always fire the listener, but...
The last commit should be squashed - I have it separate for now to highlight this interesting new edge case that comes up. |
So, we're doing all of this just for the server-side match API, right? What if the router just reached into history's internals and required |
@mjackson It's not enough in the general case - you need to go through the logic in |
One more commit we need to squash, to make sure we actually are always running through all the history enhancers (the test case is contrived, but it fails without the change, so that's good enough for me). |
Good point. But my intention never was for people to construct a history On Tue, Dec 8, 2015 at 3:50 PM Jimmy Jia notifications@github.com wrote:
|
I don't know that we have a good way to get around it. With e.g. the current router API, I like the idea of not requiring a |
This is all going to change a lot when history.listen(location => {
match(location, routes, (error, state) => {
render(...)
})
}) And I assume that would be how the internals of RouterContext will eventually look. And for SSR, it would be a simple swap: app.use((req, res) => {
match(req.url, routes, (error, state) => {
render(...)
})
}) |
Generally, stuff like query parsing is already done by the time the request hits the router on the server. In express, for example, people can do: app.use(function (req, res) {
match({
routes,
location: {
pathname: req.path,
query: req.query,
state: req.body // or session state, or whatever
}
}, ...)
}) |
Sorry, hit enter too soon. In that case, then the server wouldn't require a history object at all. We only require it right now because |
@mjackson I actually mean converting the @timdorr You don't need a |
Yeah, that's true. But it doesn't mean we have to fake a navigation to a location in history just to get it to work server side. That seems like we're missing something on |
In general it just feels wrong to be using a history object at all in a stateless environment. I'd like to find a way forward that doesn't require us to do that. Right now, |
It's tricky - you can't get the behavior demonstrated in the PR with We could introduce a new API point on |
I think the way we would do that would be to factor out the "location creation" parts from the "navigation management" parts of history. Essentially, have an immutable object that handles locations and location conversion (i.e. the current logic in I feel like this is a bigger refactoring than is practical at the moment, though. I also don't really know how this would work w/e.g. To the extent that we want to make server-side rendering less coupled with Given that, what do you think about keeping around |
If anything I think this PR has me convinced that we need to keep it around at least a little bit longer. But I'd really like to find better ways to do it in the future. |
Okay - and to be clear, to avoid breaking users, it has to be the instance method, because right now it's explicitly part of this API that I'm going to close this PR and re-submit with just the doc fixes from the first commit, so it's obvious that we didn't merge these changes. |
No description provided.