Is there any way to create a folder inside pages and add another page inside it

i would like to create a folder inside pages pages/shared and inside this folder i need to create another page… Is it possible

I tried

ionic generate page shared/newpage

but this doesnt work… this just creates a normal page with name

shared-newpage

1 Like

I don’t use the cli generators. A lot of people don’t. You can physically create folders anywhere you want. Just make sure you import their contents correctly when you want to use them elsewhere.

1 Like

Do a

ionic generate page YOURNAME

Move the generated folder in your shared folder ? Works for me

2 Likes

does manually moving the file make any error now or in future while building the app

Not for me… If you are not using the lazy method and you move the generated folder. Be sure to change the path in app.module.ts, because the CLI will create one but for the old path.

4 Likes

Thanks @Dlazzy . I will try this

And what if we are using lazy loading? How to let ionic know that my pages are not in pages folder??

I do the same as the comment above
I ionic g page MYPAGE
move it to where I need.

How does Ionic knows ?
because when you create it with the CLI - it creates a mypage.module.ts - that exports itself and expose it to the entire app, so the location no longer matters.

why the location no longer matters ?
because when you’re working with module.ts files - you’re moving between pages with:
this.navCtrl.push('myPage') ( where you simply call its name, no need to import it first etc … )

vs this.navCtrl.push(myPage), where you used to import it everywhere you needed, and used it like a variable.

Only thing need to keep in mind, is that the location of the services and other imports made inside myPage
if they were imported like import { Auth } from '../../../services/my.service; - they heirarchy of those files probably will need adjustments based on your directory location … but it’s an easy fix

1 Like

Note that after you generate the page and move it to a sub-folder, you will need to rebuild the app, or restart the app from command line so Ionic will know the location of the page. You’ll get an “invalid link” error if you just keep working :slight_smile: