Multi-page apps
A multi-page app builds several pages from one project. Each page is a separate bundle and its own Angular app, with its own bootstrapApplication(), root component and services. Use pages when a native app shows independent Lynx screens, such as a main app plus a separate settings screen.
Angular Router can't open another page, because each page is a separate app. The host app (the native iOS or Android app that runs your bundles) opens each page in its own view.
- The app that
ng build --platform iosor--platform androidgenerates shows onlymain.lynx.bundle. It copies your other bundles into the app but never opens them. - To open the others, eject the generated project and add the native code yourself (see Run on iOS and Android), or embed the bundles in your own native app.
For screens inside one app, use routing instead.
Add a page in lynx.config.ts
List each page under source.entry. The key is the page name, and the value is its entry file:
Give each page an entry file that bootstraps its own root component:
- One bundle per key.
ng buildwritesmain.lynx.bundleandsettings.lynx.bundle, plus a.web.bundleof each for the web preview. source.entryreplaces the single entry thatng buildotherwise takes frombrowserinangular.json.- Keep a page called
main. The generated native app opensmain.lynx.bundle, andng build --platformstops with an error without it. - Each page has its own providers. Give it its own
ApplicationConfig, with routes if it needs them.
Or define each page as an angular.json project
If you'd rather see each page as a project in your workspace, add one application project per page:
Then turn on the pages option in lynx.config.ts:
- Project names become bundle names. Name the first project
main, for the same reason as above. - Name a project when you run the CLI. Both projects share the workspace root, so run
ng build mainorng serve main. Either one builds every page. - All pages must share one
tsConfig. The build compiles them in a single pass and stops if they differ. pagesreplacessource.entry, so use one setup or the other.
Open each page while you develop
ng serve prints a Lynx URL and a Web URL, with a ∟ Preview link, for every page. Each one loads only that page.
- In Lynx Explorer, the QR code is for the first page. To show another page's QR code, press
rin the terminal and pick the page. You can also paste a page'sLynxURL into "Enter Card URL". - In the web preview, open the page's
∟ Previewlink. Its URL names the page's web bundle, such assettings.web.bundle.
Share data between pages
Pages don't share services, signals or router state, because each is a separate app. To pass values between them while the app runs, use LynxSessionStorage.
Limitations
- The generated native app opens only
main. See the note at the top of this page. - Each bundle carries its own copy of Angular. Two small pages are each about as big as a one-page app.
- One
tsConfigfor every page.
