Skip to content
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

Actions.reset: There is no route defined for Key X #3194

Closed
asd8855 opened this issue Aug 21, 2018 · 43 comments
Closed

Actions.reset: There is no route defined for Key X #3194

asd8855 opened this issue Aug 21, 2018 · 43 comments
Assignees
Labels

Comments

@asd8855
Copy link

asd8855 commented Aug 21, 2018

Version

  • react-native-router-flux v4.0.1
  • react-native v0.56.0
      <Tabs key="main" tabBarPosition="bottom" swipeEnabled={false} animationEnabled={false} labelStyle={styles.tabLabelStyle} tabBarStyle={styles.tabBarStyle} tabStyle={styles.tabStyle} activeTintColor="#FF4459" leftTitle=" " onLeft={() => {
          console.log("onLeft");
        }}>
        <Scene key="HomeIndexPage" component={HomeIndexPage} tabBarLabel="首页" style={{ paddingBottom: 10 }} title="首页" hideNavBar={true} icon={state => {
            let source = state.focused ? require("../../res/tab/home-icon-active.png") : require("../../res/tab/home-icon-normal.png");
            return <TabIcon source={source} />;
          }} />
        <Scene key="MoreIndexPage" component={MoreIndexPage} tabBarLabel="工作" title="工作" hideNavBar={true} icon={state => {
            let source = state.focused ? require("../../res/tab/work-icon-active.png") : require("../../res/tab/work-icon-normal.png");
            return <TabIcon source={source} />;
          }} onEnter={() => {
            Actions.refs.MoreIndexPage.table();
          }} />
        <Scene key="MineIndexPage" component={MineIndexPage} tabBarLabel="我的" title="我的" hideNavBar={true} icon={state => {
            let source = state.focused ? require("../../res/tab/me-icon-active.png") : require("../../res/tab/me-icon-normal.png");
            return <TabIcon source={source} />;
          }} onEnter={() => {
            Actions.refs.MineIndexPage.refreshHeaderView();
          }} />
      </Tabs>
    </Scene>
    <Scene key="confirmDialog" component={ConfirmDialog} />
  </Lightbox>
</Router>;

EDIT done by @daviscabral

Steps to reproduce

  • Upgrade from 4.0.0-beta.31 to 4.0.1
  • Reset from a nested scene targeting a scene that is not in the first level
@asd8855
Copy link
Author

asd8855 commented Aug 21, 2018

when I use "Action.reset("xxx")",it will show

@mswokk
Copy link

mswokk commented Aug 21, 2018

Same here.

  • RN 0.54.0
  • RNRF 4.0.1

Under 4.0.0-beta.31 has no problem.
After upgrading to 4.0.1 it throws error.

Here is my hierarchy and error message

<Router key="root">
            <Lightbox>
                <Scene key="rootScene">
                    <Scene
                        initial
                        key="entryScreen"
                        type={ActionConst.RESET}
                        component={EntryScreen}
                    />
                    <Scene
                        key="appOnboarding"
                        component={AppOnboarding}
                    />
                  (... ommit)
               </Scene>  

                <Scene
                    hideNavBar
                    key="dialog"
                    component={YDialog}
                />

                <Scene
                    hideNavBar
                    key="bottomDrawer"
                    component={BottomDrawer}
                />

                <Scene
                    hideNavBar
                    isModal
                    key="questionnaireResultModal"
                    component={QuestionnaireResult}
                />
          </LightBox>
</Router>

And I called Actions.appOnboarding() from EntryScreen which is initial scene
Error says ....

 Error: Error: There is no route defined for key appOnboarding.
 Must be one of: 'rootScene','dialog','bottomDrawer','questionnaireResultModal'

 This error is located at:
     in Navigator (at createNavigationContainer.js:376)
     in NavigationContainer (at Router.js:97)
     in App (at Router.js:122)

It looks doesn't recognize child s more then 2 depth

@mswokk
Copy link

mswokk commented Aug 24, 2018

I create a minimal project to reproduce this bug.
https://github.com/mswokk/RNRF4_test/commits/master

I found using LightBox + ActionType.RESET => this combination makes problem.

@daviscabral
Copy link
Collaborator

Nice, thanks, I'll take a look when possible and update the ticket.

@daviscabral
Copy link
Collaborator

Also guys, there a couple of things here that I noticed that are not supported anymore - due react-navigation@2 breaking changes:

I am checking the provided code now to see what is happening.

@daviscabral
Copy link
Collaborator

I found that the problem is not actually the combination between LightBox and ActionType.RESET - but the way RESET is handled now that RNRF does not manage state anymore.

What is going on - is that RESET is always called on the top stack. I'll look here what can be done in that matter.

@daviscabral daviscabral changed the title There is no route defined for Key X,Upgrading from 4.0.0-beta.31 to 4.0.1 Actions.reset: There is no route defined for Key X Sep 1, 2018
@daviscabral daviscabral self-assigned this Sep 1, 2018
@daviscabral
Copy link
Collaborator

daviscabral commented Sep 2, 2018

Hey guys - I was able to fix the issue - just being sure that is not going to break anything else before creating a PR for it.

Just to be clear about the fixes I am going to push:

  • Reset is now going to work with the right stack/scope - respecting nested scenes;
  • When using the scene aliases (Actions.[key]) for a scene that has a type RESET, it will also respect the scope.

Thank you for the patience and for keeping the discussion clear and objective here.

/cc @asd8855 @mswokk @andrew @joenoon @januswel

@Kiran0791
Copy link

I installed the latest package today "react-native-router-flux": "^4.0.1" but i don't find the above fix.
Can someone help me on how to pull these changes

@RodrigoCS
Copy link

@Kiran0791
I believe the last changes are not on npm, right now you could do react-native-router-flux@https://github.com/aksonov/react-native-router-flux/

@daviscabral
Copy link
Collaborator

This should do the trick:

yarn add aksonov/react-native-router-flux

@yqz0203
Copy link

yqz0203 commented Sep 11, 2018

@daviscabral I installed aksonov/react-native-router-flux but not working。😂😂

@Kiran0791
Copy link

aksonov/react-native-router-flux

Even after this reset not working. Its says There is no route defined for key signup.
Must be one of: 'lightbox'
. When lightbox is used it throws this error

@asd8855
Copy link
Author

asd8855 commented Oct 8, 2018

Did you solve this problem in version 4.0.5? I still had this problem in version 4.0.5
Error: There is no route defined for key main.
Must be one of: 'root','confirmDialog'

@aksonov
Copy link
Owner

aksonov commented Oct 8, 2018 via email

@asd8855
Copy link
Author

asd8855 commented Oct 8, 2018

@aksonov Replace 'reset' with 'replace'?

@aksonov
Copy link
Owner

aksonov commented Oct 8, 2018 via email

@hsynlove
Copy link

hsynlove commented Oct 9, 2018

@aksonov I have the same problem when i update my version to 4.0.5, for some reason i have to use 'reset' instead of 'replace'. What can i do?

@hsynlove
Copy link

hsynlove commented Oct 9, 2018

I find a way to avoid this problem by add a new scene 'Route' in the first place of 'Pages'.

<Lightbox>
            <Scene initial key="Start" component={StartScreen}/>
            <Scene key="Pages">
                <Scene key="Route" component={Route}/>
                <Scene key="Login" component={Login}/>
                <Scene key="Main" component={Main}/>
            </Scene>
</Lightbox>
import {Actions} from 'react-native-router-flux';

const Route = (props) => {
    const {target, params} = props;
    Actions.replace(target, params);
    return null;
};

const {reset} = Actions;

Actions.reset = (target, params) => {
    const props = {target};
    if (params) {
        props.params = params;
    }
    reset('Pages', props);
};

export default Route;

then I can use Actions.reset('Login') or Actions.reset('Main') normally. I hope this can help

@asd8855
Copy link
Author

asd8855 commented Oct 12, 2018

@hsynlove the 'Root' is empty page?

@hsynlove
Copy link

hsynlove commented Nov 7, 2018

@asd8855 yes, and this page can resolve this problem though it doesn't look elegant.

@afilp
Copy link

afilp commented Nov 25, 2018

Hi, 'replace' is not the same with 'reset' because we need to make sure that no history is tracked anymore (with back buttons, etc.) when the user logs out.

@aksonov Do you think this can be solved in a clean way? Thanks!

@ayushnawani
Copy link

ayushnawani commented Dec 28, 2018

facing the same issue here. reset not working for nested scenes with lightbox.

@spadgeaki
Copy link

@aksonov Hi, we are still experiencing the same issue in latest version.

@acollazomayer
Copy link

@aksonov same here. Just upgrade from beta to 4.0.6 and push is not working

@manithin
Copy link

same here. Reset is not working and sometimes weirdly push too is not working

@DimForCity
Copy link

yes, reset not working for nested scenes with lightbox.

@Dineshchitta
Copy link

Hi @aksonov , Trying to update
react-native-router-flux from 4.0.0-beta.22 to 4.0.6
react-navigation from 1.0.0-beta.26 -> 2.18.3
React native 59.10

Still facing this issue. If I use REPLACE instead of RESET I am not getting any issue. But the app is not behaving in expected behavior.

@malithjkmt
Copy link

malithjkmt commented Jul 28, 2019

Not working on react-native-router-flux 4.0.6 for the same scenario (Lightbox, reset)

    "react": "16.8.6",
    "react-native": "0.60.4",

Until this resolves, downgraded back to react-native-router-flux 4.0.X
@aksonov @daviscabral @asd8855 any insights ?

@sunnymopada
Copy link

@aksonov can you please reopen the issue?

@hectorsuarezm
Copy link

Same as @malithjkmt this still not working

"react": "16.9.0", "react-native": "0.61.5", "react-native-router-flux": "4.0.6"

any work around that doesn't affect the app behaviour (type="replace") ?

@mylesshie
Copy link

same error, "react-native-router-flux": "^4.2.0",

@tuandv1311
Copy link

still error, "react-native-router-flux": "4.2.0". "react-native": "0.60.4"

@sametpalitci
Copy link

Action.reset("key") the problem is fixed for me

@Nico-Guyon
Copy link

I also have the same problem with "react-native-router-flux": "^4.2.0".
Action.reset('X') gives me: There is no route defined for Key X

@yestay90
Copy link

I also face the same problem. When I add type='reset' to scene it works ok when connected to metro. But when creating build it shows error on alert that There is not route defined for Key x.

@malithjkmt
Copy link

After 2 years, upgraded to "react-native-router-flux": "^4.3.1". Still facing the same issue

@telmen
Copy link

telmen commented Jul 26, 2021

How is this closed?

@yestay90
Copy link

@telmen , I resolved this issue by resetting to Modal parent element, plus I also set initialScreen props. So, for example when you logout. Just run Actions.reset('modal'), and inside of Modal set the initialScreen.

@telmen
Copy link

telmen commented Jul 26, 2021

@yestay90 hi, i can't seem to find initialScreen prop anywhere. What do you mean by that?

@yestay90
Copy link

yestay90 commented Jul 26, 2021

@telmen , sorry it is just initial. <Scene initial={true} key="loginScreen" component={LoginScreen} />

@telmen
Copy link

telmen commented Jul 26, 2021

@yestay90 no problem, dude. But how do I reset the current stack and not use a modal scene but a plain scene from the root stack?

@yestay90
Copy link

@telmen , you get this error only when you have or which wraps you stacks. So In my case, I could only reset whether to LightBox or to Modal cause they are on top of stack.

@telmen
Copy link

telmen commented Jul 26, 2021

Decided not to use Modal :). Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests