Open peabnuts123 opened 3 years ago
Unrelatedly, I was wondering if y'all wanted to chuck the Hacktoberfest topic on this repo? This would make this PR count towards my "score" on there, and might bring in some people to make some PRs here. But I want to make this change regardless 😄
Thanks for taking the time to review @rschristian, I thought this would never be looked at
The nature of this change is to address an issue with RouterOnChangeArgs: the
previous
value is just a URL string, whilecurrent
is a component instance. Not only is it a bit uncomfortable that these are different types (while representing the same concept), it's less useful thatprevious
is just a string, when the previous route instance can be easily stored in the same manner.As far as I know this is a simple, low impact change. I've added another state property (alongside
previousUrl
) calledpreviousRoute
- this is the instance of the previous route i.e. the last value ofcurrent
. As far as I can tell,previousUrl
should map topreviousRoute
1:1 and so storing them both in the same manner should be correct behaviour.In order to not break backwards compatibility with existing applications, I have not replaced
previous
with this change, but rather, added 2 new properties (which would ideally be referenced instead, and maybe one dayprevious
andcurrent
can be removed?) calledpreviousRoute
andcurrentRoute
. You'll noticecurrentRoute
is exactly the same ascurrent
- this is to offer a migration path in the future, and to help the avoid the API feeling "clunky" (a-laDate.getFullYear()
...).Like I said I've deliberately kept this change as low-impact as possible. It could be done in better but more impactful ways, I can make these changes if you wish, just let me know.
Lastly, for some further context, I need this change in my app in order to detect when the user moves to/from a default route (i.e. I am comparing
props.default
in bothpreviousRoute
andcurrentRoute
) - it's not possible to detect this without this change. This would also allow developers to do things like extract prop values from the route as you are leaving it.