Check out example codes for "flutter clear navigation stack". It will help you in understanding the concepts better.

Code Example 1

Navigator.pushAndRemoveUntil(
      context,
      MaterialPageRoute(
        builder: (BuildContext context) => LoginPage(),
      ),
      (route) => false,
    );

Learn ReactJs, React Native from akashmittal.com