Marcos Vasquez
Marcos Vasquez

Reputation: 89

Navigate to specific route in another navigator (React Native)

I have the next route of code:

const Main = DrawerNavigator({
  Dashboard: {screen: TopNavigation},
  SetupSignUp: {screen: SetupSignUp},
},{
  initialRouteName: "Dashboard",
});

export const App = StackNavigator({
  Welcome: {screen: Welcome},
  Main: {screen: Main},
  Login: {screen: Login},
  SignUp: {screen: SignUp},
  Content: {screen: MainStack},
  SetupSignUp: {screen: }
},{
  initialRouteName: "Welcome",
});

My app start in App.

What i want is in the route of SetupSignUp from App, go to Main but in SetupSignUp, this without change the initialRouteName because i need this for use in Content.

How can i do this?

Upvotes: 2

Views: 812

Answers (2)

Tulio Braga
Tulio Braga

Reputation: 116

One alternative is to externalize your route definitions and create two similar drawer navigators with different initial routes:

const mainConfig = {};

const mainRoutes = {
  Dashboard: {screen: TopNavigation},
  SetupSignUp: {screen: SetupSignUp},
};

const Main = DrawerNavigator(mainRoutes, {
  ...mainConfig
  initialRouteName: "Dashboard",
});

const AlternativeMain = DrawerNavigator(mainRoutes, {
  ...mainConfig
  initialRouteName: "SetupSignUp",
});

Then, you will be able to navigate to Main or to AlternativeMain with different initial routes.

Upvotes: 0

Julian Corrêa
Julian Corrêa

Reputation: 668

I think you're combining Drawer and StackNavigator in the wrong way.

I made this example to try to help: https://github.com/juliancorrea/react-native-navigation-example/tree/master

Upvotes: 2

Related Questions