-
Notifications
You must be signed in to change notification settings - Fork 114
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
Impossible to have a navigate to a route multiple times #758
Comments
Have you tried using a |
@feRpicoral same thing when I use After the first click on |
This is also an issue when using dynamic routes. The url will update but the page does nothing. |
@kennethstarkrl do you have a fix or some code to fix it please? I opened an issue #768 with dynamic routes. But same problem after the fix (#713). I think this problem is the same problem. |
const { id } = useLocalSearchParams();
const [data,setData] = useState(null);
useEffect(()=>{
//clear current data
setData(null);
//get the new data
setData(newData);
},[id]); The useEffect fires when the id changes. Not sure if that will work for paths where the url doesn't change. Might be able to just do the whole router as the dependency.. const router = useRouter();
const [data,setData] = useState(null);
useEffect(()=>{
//clear current data
setData(null);
//get the new data
setData(newData);
},[router]); This is not a solution but a work around. |
Any updates? |
Ah, my issue could be the same bug. As I mentioned there, it happens only when I override default <Stack.Screen /> options in the _layout.js. So, I think there is something in default Stack.Screen props that could fix it, but I didn't find it in the project code. Could somebody help me with that? |
Upgrading expo-router to latest version (2.0.4 as at this comment) solves this issue. |
I am also facing a similar issue and I am using the latest version 2.0.5 |
I'm using expo-router 2..0.9 with a route, which doesn't have any props, the 'push' method doesn't work for me, |
// expo-router+2.0.12.patch diff --git a/node_modules/expo-router/src/global-state/routing.ts b/node_modules/expo-router/src/global-state/routing.ts
index e005d1a..413e2c6 100644
--- a/node_modules/expo-router/src/global-state/routing.ts
+++ b/node_modules/expo-router/src/global-state/routing.ts
@@ -19,7 +19,7 @@ function assertIsReady(store: RouterStore) {
}
export function push(this: RouterStore, url: Href) {
- return this.linkTo(resolveHref(url));
+ return this.linkTo(resolveHref(url), "PUSH");
}
export function replace(this: RouterStore, url: Href) {
@@ -120,7 +120,7 @@ export function linkTo(this: RouterStore, href: string, event?: string) {
case "REPLACE":
return navigationRef.dispatch(getNavigateReplaceAction(state, rootState));
default:
- return navigationRef.dispatch(getNavigatePushAction(state, rootState));
+ return navigationRef.dispatch(getNavigatePushAction(state, rootState, event));
}
}
@@ -149,10 +149,11 @@ function rewriteNavigationStateToParams(
return JSON.parse(JSON.stringify(params));
}
-function getNavigatePushAction(state: ResultState, rootState: NavigationState) {
+function getNavigatePushAction(state: ResultState, rootState: NavigationState, type = "NAVIGATE") {
const { screen, params } = rewriteNavigationStateToParams(state);
+
return {
- type: "NAVIGATE",
+ type,
target: rootState.key,
payload: {
name: screen, |
The thing what work for me was update the version of expo router (from 2.0.0 to 2.0.5) |
# Why `router.push()` should always most history forwards. However we are currently using the `NAVIGATE` action which may move history backwards if the screen is in history and the closest navigator is a Stack. Adds `router.navigate` for when users wish to opt out of this behaviour. Fix: expo/router#758 Fix: expo/router#741 Keeping this in draft until #24598 is merged # How This changes `router.push()` to a PUSH action if the lowest nested navigator is a stack and shared between the old & new routes. Otherwise it defaults back to NAVIGATE. # Test Plan Included test case # Checklist - [ ] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). --------- Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com> Co-authored-by: Evan Bacon <bacon@expo.io> Co-authored-by: Aman Mittal <amandeepmittal@live.com> Co-authored-by: Bartosz Kaszubowski <gosimek@gmail.com>
For future readers: I came to this post for the same problem, but updating the package did not work for me. |
…4600) # Why `router.push()` should always most history forwards. However we are currently using the `NAVIGATE` action which may move history backwards if the screen is in history and the closest navigator is a Stack. Adds `router.navigate` for when users wish to opt out of this behaviour. Fix: expo/router#758 Fix: expo/router#741 Keeping this in draft until expo#24598 is merged # How This changes `router.push()` to a PUSH action if the lowest nested navigator is a stack and shared between the old & new routes. Otherwise it defaults back to NAVIGATE. # Test Plan Included test case # Checklist - [ ] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). --------- Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com> Co-authored-by: Evan Bacon <bacon@expo.io> Co-authored-by: Aman Mittal <amandeepmittal@live.com> Co-authored-by: Bartosz Kaszubowski <gosimek@gmail.com>
# Why `router.push()` should always most history forwards. However we are currently using the `NAVIGATE` action which may move history backwards if the screen is in history and the closest navigator is a Stack. Adds `router.navigate` for when users wish to opt out of this behaviour. Fix: expo/router#758 Fix: expo/router#741 Keeping this in draft until expo/expo#24598 is merged # How This changes `router.push()` to a PUSH action if the lowest nested navigator is a stack and shared between the old & new routes. Otherwise it defaults back to NAVIGATE. # Test Plan Included test case # Checklist - [ ] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). --------- Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com> Co-authored-by: Evan Bacon <bacon@expo.io> Co-authored-by: Aman Mittal <amandeepmittal@live.com> Co-authored-by: Bartosz Kaszubowski <gosimek@gmail.com>
Which package manager are you using? (Yarn is recommended)
npm
Summary
Hi,
Thank you so much for your job and expo router!
I tried expo router and I have an issue: I can't navigate to a route multiple times as react navigation (Navigate to a route multiple times):
Minimal reproducible example
I tried with this code, but not work:
The text was updated successfully, but these errors were encountered: