I’m starting out with the Ionic Framework and I’m a bit confused on how to correctly set up my Routes.
On first boot, my app contains a IonRouterOutlet
which decides to either render Login
or App
if the user is already logged in:
<IonRouterOutlet id="main">
<Route path="/app" render={() => <App />} />
<Route
path="/login"
render={({ history }) => <Login history={history} />}
/>
<Route exact path="/" render={() => <Redirect to="/login" />} />
</IonRouterOutlet>
On successful login, I want to navigate to /app
.
const history = useHistory()
const doLogin = (payload: any) => {
history.replace('/app')
};
Here I use replace
as I don’t want users to be able to go back to the login page by swiping back.
Unfortunately this also means that there is no animation between /login
and /app
, which doesn’t look great.
What’s the correct way to do this navigation? The docs seem a bit sparse on how to use Navigation component in a real world example.