https://github.com/aaronksaunders/mysimpletabsapp
Working with the new ionic cli generating an app with tabs and a login page
https://github.com/aaronksaunders/mysimpletabsapp
ionic-framework ionic4 login reactjs tabs
Last synced: about 1 year ago
JSON representation
Working with the new ionic cli generating an app with tabs and a login page
- Host: GitHub
- URL: https://github.com/aaronksaunders/mysimpletabsapp
- Owner: aaronksaunders
- Created: 2019-06-05T04:22:50.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-13T18:23:53.000Z (over 6 years ago)
- Last Synced: 2025-01-21T20:11:27.093Z (about 1 year ago)
- Topics: ionic-framework, ionic4, login, reactjs, tabs
- Language: CSS
- Homepage:
- Size: 239 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mySimpleTabsApp
Working with the new ionic cli generating an app with tabs and a login page
##Getting Started
use the ionic cli to build your app, make sure you specify react and we are going to use the tab starter as our baseline and then move some things around to get the desired results.
>See blog post for more detailed instructions on getting started
Enter into console, and when prompted select `tabs` as the starter template
```
$ ionic start myApp --type=react
```
So lets clean up some of this and create a more structured starting point.
Create a new file called `TabRoot.tsx` and copy everything from inside of the `IonApp` element in `App.tsx` over to the new component. When you are done, `App.tsx` should look like this
```tsx
const App: React.SFC = () => (
} />
);
```
Remove this line
```tsx
} />
```
Then add the new default `Route` to point to the `TabRoot` component we just built
```tsx
const App: React.SFC = () => (
);
```
And `TabRoot.tsx` should look like this after pasting the code we cut from `App.tsx`.
>Please note I have removed the imports to save space when looking at the code. I also have reduced the number of tabs from three to two, I believe that is sufficcient to make my point.
```tsx
interface IAppProps {}
const TabRoot: React.FC = props => {
return (
Tab One
Tab Two
);
};
export default TabRoot;
```
Now the application is set up such that the default route is to render the `TabRoot` component, but we need to tell the component which to render and we want it to be
```html
} />
```
### Why Bother?
Having all of the default routing based around tabs at the route level of the application can become problematic as the application gets more complex. As you will see in the later sections when the app has to check for authenticated user and protected routes, this setup will be beneficial
### Cleanup Tab1
There is alot of noise in `Tab1` so lets make it look like tab2, copy contents from `Tab2` into `Tab1`
```tsx
import React from 'react';
import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/react';
const Tab1: React.SFC = () => {
return (
<>
Tab One
>
);
};
export default Tab1;
```
## Navigating to Detail Pages
Lets just copy `Tab1.tsx` and rename it `Tab1-Detail.tsx`... clean it up so it looks like this when you are done.
```tsx
import React from 'react';
import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/react';
const Tab1Detail: React.SFC = () => {
return (
<>
Tab One Detail
>
);
};
export default Tab1Detail;
```
Add button in the content section of `Tab1`; we will use that button to navigate to the detail page `Tab1Detail` that we just created.
```tsx
{
e.preventDefault();
props.history.push("/tab1-detail");
}}
> NEXT PAGE
```
So a few problems when you make this change, the first one is
>Where are the props.history coming from?
We can use react-router `withRouter` to get the `history` object passed along as a property to the component
```tsx
// add the import..
import { withRouter } from "react-router";
```
Then add parameter, and for now we will specify the type as `any`
```tsx
const Tab1: React.SFC = (props) => {
```
Finally we need to add the actual route to the `Router` element in `TabRoot`, So add the new route.
```tsx
} />
```
Now to go back, we need to first add the `IonBackButton` component to the toolbar on the `Tab1Detail` page