-
Notifications
You must be signed in to change notification settings - Fork 113
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
WARN The redirect
prop on <Screen /> is deprecated and will be removed. Please use router.redirect
#834
Comments
Please provide a full reproduction. Creating a new project I'm going to close this issue, but if you can provide information we can reopen it again. |
I had a similar issue on my side and what caused it was this code:
If you remove it the warning will go away (not a solution I know) |
I think issue is here perhaps
if you look at the code, if you do this for example:
Then deprecated would end up being
Then looking at
the Unless I am completely wrong, anyone using stack.screen would end up with a warning, should this issue be reopened ? PR here: expo/expo#23932 |
This code was introduced with the |
@sync yes, I can confirm that just using Reverting to |
yes waiting for someone to review this: expo/expo#23932 :-) |
…when using Screen (#23932) # Why WARN The redirect prop on <Screen /> is deprecated and will be removed. Please use router.redirect, fixes expo/router#834 I think issue is here perhaps https://github.com/expo/router/blob/f69e31c84a83ceb6d678dfb8aeed708974d301a8/packages/expo-router/src/views/Screen.tsx#L49 if you look at the code, if you do this for example: ``` <Stack.Screen options={{ title: params.name, }} /> ``` Then deprecated prop would end up being `undefined` because `redirect` would not be set ``` useDeprecated( "The `redirect` prop on <Screen /> is deprecated and will be removed. Please use `router.redirect` instead", redirect ); ``` Then looking at `useDepecated` code here: ``` export function useDeprecated( message: string, guard: unknown = true, key = message ) { return useWarnOnce(key, guard, `Expo Router: ${message}`); } ``` the `guard` would end up being set to `true` because of the default value `guard: unknown = true` # How Avoid sending an undefined `redirect` prop to the guard # Test Plan Run updated code and make sure warning is gone # Checklist <!-- Please check the appropriate items below if they apply to your diff. This is required for changes to Expo modules. --> - [x] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [x] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [x] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). --------- Co-authored-by: Evan Bacon <baconbrix@gmail.com> Co-authored-by: Lucas Caton <lucascaton@gmail.com>
also confirmed this exists, thanks for the pr |
When can we expect a fix? |
Same issue here, pretty annoying |
Agree - let's get it fixed In my case it is caused by:
|
Can confirm this is still a problem, v 2.0.5 |
Same! Still annoying. It wasn't showing from a project I spun up a few days ago... But now it is showing. |
on expo router
Prior to upgrading, I was able to declare my screen options like this in my component, that is no longer the case After removing this, and setting the screen options in the declared stack, the warning went away. |
Can you show an example of how you do that? |
in
|
solved! |
Remove this chunk of code from the screen <Stack.Screen screenOptions={{ headerShown: false }} /> Now you can use this screen configuration in _layout. |
This shouldn't be the solution since sometimes there is logic you want to apply from the screen. For example, you may want to modify the |
I agree, it is very useful to use it within the page, this feature should not be removed. |
I agree but nothing to do! They should have kept both in place. |
When I do Does anyone know why or how to remove that |
Is this warning a critical issue or can we ignore it? |
you can ignore it until this is removed in future version of expo router, my assumption is that it won't be removed until v3 but I could be wrong. |
The solution, although confusing, is to move your declarations to
It seems meaningful for Expo Router to continue to support the ability to specify Stack.Screen (as it did in v2.0.0, i believe) on a per screen basis (as this is often required and react-navigation supports it, so expo-router should). I'm curious why the Expo team opted to remove/change this? |
Having this issue right now and its driving me crazy, hope it gets fixed soon |
The fix is merged for version 3 in the expo/expo repository. The linked PR is the backport of that fix for version 2, which is the "latest" version on npmjs. The fact that this is "just" a warning doesn't help here. It causes a pop-up in developer mode and spams my console. |
Why can this not be backported to a 2.0.x release? This is incredibly annoying. |
Same here. Very frustrated. |
At this point lets just switch to react nav |
frustrating. |
How else do you change the header components in a dynamic view?
I have <Stack.Screen
options={{
title: data?.name ?? '',
}}
/> Producing the same error as everyone else. I just need to set the title of my view based on the data that I've fetched. |
Can this issue be reopened? This seems important to fix. |
Re-open it, please 🙃 |
pinging @marklawlor, in case. |
Here's a different workaround that has the advantage of maintaining the "page + options" colocation. import React from 'react';
import { View} from 'react-native';
import { Link, Stack } from 'expo-router';
- import { Stack } from 'expo-router';
+ import { useNavigation } from 'expo-router';
export const HomeScreen = () => {
+ const navigation = useNavigation();
+
+ React.useEffect(() => {
+ navigation.setOptions({
+ headerShown: false,
+ });
+ }, [navigation]);
return (
<View>
- <Stack.Screen options={{ headerShown: false }} />
<Text>Home</Text>
</View>
);
}; If that doesn't work whatever reason, the other workaround is is to move the Hope that helps! |
Clarifying feature options RE: expo/router#834 (comment)
If you want to keep doing stuff the old way in v2, you can patch it yourself. Someone asked me above how to do it so here's how: just install patch-package from npm, or use the built in approach if your package manager supports it. All you have to do is add made a short blog post on it if anyone needs more help than that. |
With this example, there has a display issue on my cell phone. |
@danstepanov You are right. I did the same thing to solve this issue, as same as you. So, yes, this works! |
Why is this issue closed?? |
@marklawlor, this is easily reproducible, can you please reopen? |
issue described in this issue expo/router#834
I guess between moving Expo Router upstream into the main Expo repo, and the imminent release of v3 the team are ignoring or deprioritising anything related to v2. I know we are on the bleeding edge but I think it’s a bit cavalier to leave v2 in an imperfect state like this and expect people to patch or do a major version upgrade. I think it damages adoption, because v3 is not live yet and new users are installing this every day and possibly turning away because of small issues like this. 🤷♂️ |
issue described in this issue expo/router#834
issue described in this issue expo/router#834
As a workaround, while we wait for this to be patched in v2 I've found that you can suppress the warning by adding the following to the root of your app: import { LogBox } from 'react-native';
LogBox.ignoreLogs([
'The `redirect` prop on <Screen /> is deprecated and will be removed. Please use `router.redirect` instead'
]); Not the best solution but saves faffing with patch package etc. |
fyi: it seems to be fixed now in (see commit 9f8a67b) |
Yes its fixed!! Thanks!! |
Adds section to stack.mdx showing alternative method to configure screen options from route, via imperative API # Why Clarifying feature options following discussion in this issue: expo/router#834 (comment) # Checklist <!-- Please check the appropriate items below if they apply to your diff. This is required for changes to Expo modules. --> - [x] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [x] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [x] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). --------- Co-authored-by: Aman Mittal <amandeepmittal@live.com>
Adds section to stack.mdx showing alternative method to configure screen options from route, via imperative API # Why Clarifying feature options following discussion in this issue: expo/router#834 (comment) # Checklist <!-- Please check the appropriate items below if they apply to your diff. This is required for changes to Expo modules. --> - [x] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [x] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [x] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). --------- Co-authored-by: Aman Mittal <amandeepmittal@live.com>
Which package manager are you using? (Yarn is recommended)
yarn
Summary
from the example from expo router docs
when running the for dynamic route
The text was updated successfully, but these errors were encountered: