I am using ionic-cli 2
for generating pages for my ionic
project. I would like keep my pages separately in different folders . For example , I would like to keep pages like Login
, Signup
in a separate folder called authentication
. But at the same time I would like to enjoy the ionic generate page
command to quickly setup the page inside the authentication
folder. Currently ionic-cli
would generate the pages in pages
folder. How can I make it in pages/authentication
folder ?

- 5,989
- 7
- 30
- 62
6 Answers
I know it's been a while, but this worked for me using the @latest ionic (3.12.0)
Generate "sub-pages" from the app's root folder as you would generate "top-level" pages. Then, drag them to their intended place using Visual Studio Code.
Obviously you want to rename stuff such as modules and classes. For example, for the 'home' and 'standings' sub-pages of the 'team' page, I renamed the classes from HomePage
and StandingsPage
to TeamHomePage
and TeamStandingsPage
respectively.
Alternatively (and in retrospect recommended), name the pages using the desired structure, e.g., ionic generate page team-home
(you'll still have to move them manually). This is especially useful for repeating patterns, e.g., if you also want 'home' and 'standings' sub-pages for say a 'tournaments' page.
Also see Can ionic2's pages support nested directory structure?.

- 771
- 8
- 21
Just run
ionic generate page pages/authentication
more information https://ionicframework.com/docs/cli/commands/generate

- 5,404
- 2
- 26
- 39
-
This does not address the question. The command will generate page named "pages-authentication" under folder "pages". The question ask how to generate pages under pages/authentication. – Ahmed Bahtity Aug 29 '21 at 07:53
-
this exactly addresses the question. COMMANDS for the @raj would be .....`ionic generate page authentication/login ` AND `ionic generate page authentication/Signup` – iWasCloud Feb 24 '22 at 06:15
Reading the doc https://ionicframework.com/docs/cli/commands/generate Seems that you can specify the folder where you want to generate your page or component directly when you call the command.
Typing ionic g page my_dir/my_page
generate a page component into the my_dir directory.

- 900
- 1
- 9
- 14
-
1erroneous assumption as this in later versions will generate a page and folder named my_dir-my_page – Mbithy Mbithy Jan 12 '20 at 10:07
I know this gets tricky in the beginning. Here, I'm mentioning the steps to create a page under specific directory.
Suppose your project follows the structure of directory as:
- src
- app
- components
- pages
- pipes
- components
- app
To create a page under "pages", navigate to "app" directory and use command: ionic g page pages/test
Reference: https://ionicframework.com/docs/cli/commands/generate

- 1
- 3
before creating a separate folder you have to manually create an authentication folder into your app folder.
CLI > ionic generate page authentication/login

- 11
- 3