Replies: 35 comments 11 replies
-
The problem is that it does not replace |
Beta Was this translation helpful? Give feedback.
-
Also, if react-router wants to gain traction in react-native land then you'll need to be able to support stack navigation. Please see #7943 for details. |
Beta Was this translation helpful? Give feedback.
-
Hi, I hadn't seen this discussion and created a PR for adding |
Beta Was this translation helpful? Give feedback.
-
I'm not sure Maybe a more explicit name would be clear: The point of the |
Beta Was this translation helpful? Give feedback.
-
This update feels wrong. The |
Beta Was this translation helpful? Give feedback.
-
@sebastian-nowak |
Beta Was this translation helpful? Give feedback.
-
As far as I can tell, animation is the only real use case for the The modal gallery that some here have pointed out is actually busted. If you refresh the page when the modal is open, you go to the actual page for that color without the modal. We should probably rebuild that example using |
Beta Was this translation helpful? Give feedback.
-
Refreshing the page to have the modal go away is actually the intended behavior. It's not busted. It's the exact same behavior used on Reddit when opening a comment thread. Within the same page load, it pops a full height modal to show the thread, leaving the thread list behind it. If you refresh the page, it's just the comment thread and no modal overlay. This is important to browsing threads, as the order of the thread list changes rapidly. If you lose the state of the thread list when going back you would end up having threads disappear on you regularly. Retaining prior state while navigating is super important for their UX. They use React Router and I'm not sure how they'd upgrade to v6 without a location prop. |
Beta Was this translation helpful? Give feedback.
-
@mjackson I hope I’m not being a nuisance but I have a good bit of experience in react-native and I have concerns that v6 won’t be a viable option for react-native without the location prop. With mobile apps, users expect to be able to use operating system gestures (or emulated gestures) to navigate around the app. The most common and important of these gestures is the swipe-back gesture. Below is a GIF I found that hopefully illustrates this gesture clearly. As you can see, after I navigate to a new screen I need to be able to swipe that screen away and see the previous screen underneath. People call this stack-navigation because it looks like you’re swiping away cards in a stack of cards. The tricky thing here is you should be able to have an arbitrary number of cards in the stack. So if I go from screen A -> B -> C then the stack should be [A, B, C]. As an optimization, I only need to render the two most recent cards [B, C]. However, if I swipe away C then I need to be able to render A again. I’m not sure AnimatedRoutes with its key-based solution would be able to inject the correct location back into A after it has unmounted. It may be clearer to see code so I included a WIP implementation of this gesture in issue #7943. Otherwise, I love the v6 API so far! |
Beta Was this translation helpful? Give feedback.
-
My use case is similar to the modal example but a bit more complex, and related to the discussion. I have not been able to implement the current functionality in V6, since I am missing the location prop. There might be another way but I haven't found it, so excuse me if that's the case. You can check it if you visit our demo project (you can just skip de login)
If you open the same product url in a new window you get the same side dialog, but the base collection is now I could not replicate this without overriding the location prop in routes. For the rest, the V6 api is much better in my opinion and allows us to provide better routes customization to our users. |
Beta Was this translation helpful? Give feedback.
-
That's exactly why I've used I.e if you're opening a details page in modal, you're seeing it on top of feed (without losing feed position, etc) but if you send the same link to your friend, they do not need to see the feed you were scrolling, post could have been in any/personal feed. I can't think of a better idea to build that functionality but if there's any, I'm all ears. |
Beta Was this translation helpful? Give feedback.
-
We use react-router in Todoist for the settings, which are provided in a modal UI, and the modal routing works great. What we do is that we internally set a default background URL for when the modal was not triggered by the user, but the URL was visited directly. In this case, the users get the view with the settings modal open right from the start, and the background renders the default view we set. When the users close the settings modal, they land on this view as the initial one (which would've been the page they'd get anyway if they start by visiting https://todoist.com/app). Here's a demo: CleanShot.2021-08-28.at.18.54.58.mp4I trigger the modal from a view called "upcoming", the URL changes fully to not encode anything about the upcoming view being visible underneath. But the upcoming view is still underneath, and all its state preserved if the user closes the settings. In the video, however, I did not close the settings, but I refreshed. You can see that in that case I no longer get the Upcoming view underneath, but the Today view instead (with the settings modal open on top). This is the view I'd get if I visited the app's root path anyway. This is all working, inspired by the modals example in v5 documentation. So I would not call it busted. And the approach is great because it allows us to have users open the settings for a quick tweaking, without loosing any transient state in the page underneath (e.g. they may be in the middle of adding a task that's not yet saved, etc). |
Beta Was this translation helpful? Give feedback.
-
@timdorr No it isn't :) Sorry, I shouldn't have just said the modal example was busted without digging a bit further. It turns out the example code isn't actually busted, just the Codesandbox browser is. My original point stands though; the modal should still be open after a page refresh. This is because Here's how it should work (running in Chrome): Notice how after the page refresh the modal is still open. Here's the broken behavior I mentioned, where the modal is not still open after the page refresh (running in the Codesandbox browser in our docs): Notice how after the page refresh the modal isn't open anymore. That's busted. My guess is the Codesandbox browser doesn't support
@gitcatrat Yes, we agree the modal should not be there in a new window (i.e. your friend's). But if all you're doing is refreshing the existing page (same user, not your friend) you should still see the modal in our example. But anyway, getting back to the original discussion: it's fairly easy to mimic the current modal example without the
I put some state in the So again, I don't think that modals are a good use case for maintaining the |
Beta Was this translation helpful? Give feedback.
-
What if what I need to render in the background is not always the same, but actually driven by an actual location value that's not just boolean? Imagine I have a grid (gallery) view at How can we know here what background to render: |
Beta Was this translation helpful? Give feedback.
-
@gnapse Use a string instead of a boolean. <Route
path="/img/:id"
children={
background === "gallery" ? (
<>
<Gallery />
<Modal />
</>
) ? background === "list" ? (
<>
<List />
<Modal />
</>
) : (
<ImageView />
)
}
/> |
Beta Was this translation helpful? Give feedback.
-
One idea I just had: <TransitionGroup>
<AnimatedRoutes animator={CSSTransition}> Just |
Beta Was this translation helpful? Give feedback.
-
@timdorr The We use |
Beta Was this translation helpful? Give feedback.
-
@mjackson, it is not that it is ugly. It's the fact that I'd be replicating what react-router already does really well: mapping a location to something that should be rendered for that location. Not just that, there are things that I suspect are impossible. Because react-router's algorithm to map locations to elements goes beyond a mere
What if the location that's used to decide whether to render Do you have a suggestion on how to solve that in user land without the location prop? Even if it's ugly? |
Beta Was this translation helpful? Give feedback.
-
Why
|
Beta Was this translation helpful? Give feedback.
-
@CooCooCaCha I just remembered that you had said this, and I wanted to let you know that React Native support is not a goal for us in v6. We have supported React Router on React Native for several years now, but haven't seen very much engagement from the React Native community, unfortunately. So we are not planning on shipping v6 for React Native. |
Beta Was this translation helpful? Give feedback.
-
That's quite unfortunate to hear. If I'm being honest, I've been following react-router for awhile and I actually got the impression that you all never wanted to support react-native in the first place. Perhaps the community picked up on that too and went a different route. Anyways, best of luck. |
Beta Was this translation helpful? Give feedback.
-
Coming from React DOM world I find out extremely useful to be able to use react-router based components in both web and native version of the app I'm developing. Saves me a ton of time. Do you think there's anything we could do to help releasing RR6 for RN as well? Including financially. |
Beta Was this translation helpful? Give feedback.
-
@ryanflorence I like your solution, but why don't we add a function Outlet({ animated = false }) {
const currentOutlet = useOutlet();
const prevOutlet = useState( currentOutlet );
return (
animated
? prevOutlet
: currentOutlet
);
} |
Beta Was this translation helpful? Give feedback.
-
@CooCooCaCha I'm sorry you got that impression. We've been shipping react-router-native for a few years now and keeping it up to date. I'm not sure what more we could've done to prove that we wanted to support RN.
@wojtekmaj The code is already there in v6, so we have decided to go ahead and ship it. Thanks for the offer to help. |
Beta Was this translation helpful? Give feedback.
-
@mjackson What's the plan for adding |
Beta Was this translation helpful? Give feedback.
-
Is there any update on how to animate routes with RRv6? Particularly when leaving a route (unmounting). |
Beta Was this translation helpful? Give feedback.
-
I have some problem like this. its about route animate its demo codesandbox what should i do if i want animate route? |
Beta Was this translation helpful? Give feedback.
-
I think 0004-06-19.15.43.23.mov |
Beta Was this translation helpful? Give feedback.
-
@mjackson, this discussion seems to be too old to appear in your weekly live streamings but I think it deserves to be reconsidered. |
Beta Was this translation helpful? Give feedback.
-
Maybe the view transition api killed the game. |
Beta Was this translation helpful? Give feedback.
-
What is the new or updated feature that you are suggesting?
React Router v6 should include first-class primitives for supporting animations on route transitions.
A bit of history here: in v4/5, we added the
<Switch location>
prop. This prop provided a way for you to keep the<Switch>
rendering an old location when it is rendered inside another element with akey
that is used to perform an animation, such as a<CSSTransition>
from react-transition-group. It looked something like this:This API worked fine for v4 and v5, but it's not entirely clear outside of the context of animations that the
<Switch location>
prop is to be used for animations. It was proposed in #7117 that we add a<Routes location>
prop that could be used in v6. However, since v6 is built entirely on React hooks, I think we can do better.Instead of a
location
prop, we can provide "animated" versions of all components and hooks that give you elements to render. So, for example, the animated version of<Routes>
would be<AnimatedRoutes>
. You could use it exactly like<Switch location>
, except it's much more clear what it's for.In addition to
<AnimatedRoutes>
we can also provide:<AnimatedOutlet>
useAnimatedRoutes()
useAnimatedOutlet()
Each of these elements and hooks would ofc work exactly like the non-animated version but with one important difference: they don't subscribe to location updates from context. Instead, they must be used inside another element with a
key
that will be unmounted in the transition.AFAICT all animation libraries for React work this way. They rely on a
key
changing on an element to know when an element is going to transition out/in.Why should this feature be included?
Providing animation primitives should make it easier for people to do animations between routes.
Beta Was this translation helpful? Give feedback.
All reactions