Adding new page in ionic
In Ionic, you can add a new page to your app by following these steps:
Method 1: Using the Ionic CLI
- Open your terminal and navigate to your Ionic project directory.
- Run the command
ionic generate page <page-name>
to create a new page. For example,ionic generate page login
. - This will create a new directory with the page's files, including the HTML, CSS, and TypeScript files.
- Open the
login.page.html
file and add your page's content, such as HTML elements and Angular directives. - Open the
login.page.ts
file and add your page's logic, such as Angular components and services. - Update the
app-routing.module.ts
file to add a new route for the new page.
Method 2: Manually creating a new page
- Create a new directory in your project's
src
directory, for example,login
. - Inside the
login
directory, create the following files:login.page.html
: the HTML file for the pagelogin.page.css
: the CSS file for the pagelogin.page.ts
: the TypeScript file for the page
- Add your page's content and logic to the respective files.
- Update the
app-routing.module.ts
file to add a new route for the new page.
Adding the new page to the app
- Open the
app-routing.module.ts
file and add a new route for the new page. For example:import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { LoginPage } from './login/login.page';
const routes: Routes = [ { path: '', component: TabsPage }, { path: 'login', component: LoginPage } ];
@NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule] }) export class AppRoutingModule {}
2. Update the `app.component.html` file to include a link to the new page. For example:
```html
<ion-app>
<ion-router-outlet></ion-routerlet>
<ion-nav [root]="root"></ion-nav>
</ion-app>
- Run the command
ionic build
andionic serve
to build and serve your app.
That's it! You should now have a new page in your Ionic app.