Navigating between pages is a core feature of any mobile application. Let’s look at how we can achieve this with React, React Router and Ionic 4.
For this article, I’m going to assume that you have a React and Ionic 4 application already up and running. If you haven’t done this yet - visit my article on Alligator.io that covers this already.
The core dependencies we’ll need for this project are the following:
For routing to work, we’ll need some pages to route between. Let’s create two new files at src/pages/HomePage.js
and src/pages/BlogPage.js
This allows us to define a HomePage
:
And a BlogPage
:
We can then define the routes for our application inside of App.js
:
While we could just define our Route
with react-router-dom
only, placing the Route
inside of an IonRouterOutlet
will enable animations within route changes.
Navigating between two pages is therefore as easy as taking history
from props
and pushing a new Page
onto the stack.
Let’s update the HomePage
to accommodate this:
Pretty simple to achieve as you can see! Here’s the results of our work:
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
How to pass value from homepage to blogpage