Initialize App

After we have our app layout now we need to mount Svelte components and initialize the app. You can read about all possible Framework7 initialization parameters in appropriate Framework7 App Parameters section.

We have the following HTML structure in our index file:

  1. <!-- index.html -->
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <!-- ... metas and styles ... -->
  6. <link rel="stylesheet" href="path/to/framework7.bundle.min.css">
  7. </head>
  8. <body>
  9. <!-- App Root Element -->
  10. <div id="app"></div>
  11. <script type="text/javascript" src="path/to/app.js"></script>
  12. </body>
  13. </html>

In addition, if you’re using Rollup or Webpack, you might typically have a root-level app.js or index.js file that mounts your root app component:

  1. // app.js
  2. // Import F7 Bundle
  3. import Framework7 from 'framework7/framework7-lite.esm.bundle.js';
  4. // Import F7-Svelte Plugin
  5. import Framework7Svelte from 'framework7-svelte';
  6. // Init F7-Svelte Plugin
  7. Framework7.use(Framework7Svelte);
  8. // Import Main App component
  9. import App from './App.svelte';
  10. // Mount Svelte App
  11. const app = new App({
  12. target: document.getElementById('app'),
  13. });

Your root App.svelte component will typically have a top-level Framework7App component. This component is used to configure your app:

  1. <!-- App.svelte -->
  2. <!-- Main Framework7 App component where we pass Framework7 params -->
  3. <App params={f7params}>
  4. <!-- initial page is specified in routes.js -->
  5. <View main url="/" />
  6. </App>
  7. <script>
  8. import { App, View, Page, Navbar, Toolbar, Link } from 'framework7-svelte';
  9. import routes from './routes.js';
  10. const f7params = {
  11. // Array with app routes
  12. routes,
  13. // App Name
  14. name: 'My App',
  15. // App id
  16. id: 'com.myapp.test',
  17. // ...
  18. };
  19. </script>

In the examples above:

  • we pass Framework7 parameters to the App main Framework7 app component in its params property;
  • root element used as App target (document.getElementById('app')) will be used as Framework7 root element

We also must specify array with routes (if we have navigation between pages in the app). Check out information about Svelte Component Extensions, router and routes in the Navigation Router section.

← App Layout

Svelte Component Extensions →