score:193

Accepted answer

react navigation 3.0 has a number of breaking changes including an explicit app container required for the root navigator.

in the past, any navigator could act as the navigation container at the top-level of your app because they were all wrapped in “navigation containers”. the navigation container, now known as an app container, is a higher-order-component that maintains the navigation state of your app and handles interacting with the outside world to turn linking events into navigation actions and so on.

in v2 and earlier, the containers in react navigation are automatically provided by the create*navigator functions. as of v3, you are required to use the container directly. in v3 we also renamed createnavigationcontainer to createappcontainer.

also please note that if you are now using v4, navigators have been moved to a separate repo. you'll now need to install and import from 'react-navigation-stack'. for example import { createstacknavigator } from 'react-navigation-stack' the solution below is for v3.

import {
  createstacknavigator,
  createappcontainer
} from 'react-navigation';
const mainnavigator = createstacknavigator({...});
const app = createappcontainer(mainnavigator);

a more comprehensive code example:

import {
      createstacknavigator,
      createappcontainer
    } from 'react-navigation';
import login from './view/login.js'
import signup from './view/signup.js'

const rootstack = createstacknavigator({
    home: {
      screen: login
    },
    signup: {
      screen: signup
    }
  });

const app = createappcontainer(rootstack);

export default app;

score:-2

i been struggling from past few days .well might be you too been struggling to solve if and if you have deleted the react-navigation from package.json and installed using npm please check your backup project and see the navigation version and try to add the same and remove node-modules and do npm install. hope its works.

good luck breaking your head with react-native :-)

score:2

import react, { component } from 'react';
import { createstacknavigator, createappcontainer } from 'react-navigation';
import home from './home';
import details from './details';

const root = createstacknavigator({

    home: { 

        screen: home,
    },

    details: { 

        screen: details,
    },

});

const container = createappcontainer(root);
export default container;   

in your app.js file reference it with </container>

score:2

i had the code at the bottom

export default class app extends react.component {
  render() {
    return (
      <view >
        <simpleapp style={{ width: dimensions.get("window").width }} />
      </view>
    );
  }
}

i simply replaced it with and it worked like a charm. definitely, it's because updates in react-navigation library:

const app = createappcontainer(simpleapp);
export default app;

also, i included createappcontainer library into react-navigation at the top as well.

score:2

this one is to create a bottom navigator with two tabs:

import {createbottomtabnavigator, createappcontainer} from 'react-navigation';

export class home extends component{
   //...
}

export class settings extends component{
   //...
}     

const navig = createbottomtabnavigator({
  home: home,
  settings: settings
});

const app = createappcontainer(navig);

export default app;

score:3

const appnavigator = createstacknavigator({
  home: { screen: home },
  friends: { screen: friends },
});

simple i did

const app = createappcontainer(appnavigator);
export default app;

instead of

export default appnavigator;

score:6

here's another way

import react, {component} from 'react';
import { stylesheet, text, view } from 'react-native';
import { createstacknavigator,createappcontainer } from 'react-navigation';

import login from './view/login.js'
import signup from './view/signup.js'

const rootstack = createstacknavigator(
  {
    home: {
      screen: login
    },
    signup: {
      screen: signup
    }
  },
  {
    initialroutename: 'home'
  }

);

class app extends react.component {
  render() {
    return <rootstack />;
  }
}

export default createappcontainer(rootstack);

score:7

i wasted my 2.5 hours to got this solution after many google searches...hope this will work.

just import this two:

import { createstacknavigator } from "react-navigation-stack";
import { createappcontainer } from "react-navigation";

and make a little change to your code like this:

create const above the class

const appnavigator = createappcontainer(rootstack);

and finally call that const in the class instead of <rootstack/>

<appnavigator />

thankx!

score:11

create a new file screencontainer.js (you can choose the name). then in the screencontainer file add:

import react, { component } from 'react';
import { createstacknavigator, createappcontainer } from 'react-navigation';
import mainscreen from './mainscreen'; 
import aboutscreen from './aboutscreen';

const navigationstack = createstacknavigator({
    main: { 
        screen: mainscreen,
    },
    about: { 
        screen: aboutscreen,
    },
});

const container = createappcontainer(navigationstack);

export default container; 

then at your app.js file:

import container from './screencontainer';

class app extends component {
  render() {
    return (
      <container />
    );
  }
}

score:26

@tom dickson something like this:

import react, { component } from 'react';
import { createstacknavigator, createappcontainer } from 'react-navigation';

import screenone from './screenone';
import screentwo from './screentwo';

const navstack = createstacknavigator({
    screenone: { 
        screen: screenone,
    },
    screentwo: { 
        screen: screentwo,
    },
});

const app = createappcontainer(navstack);

export default app;

then reference it with

<app />

Related Query

More Query from same tag