Initialize App

Now you can see our HTML layout with linked required CSS and JavaScript files. Now we should initialize our app (for example in my-app.js):

  1. var app = new Framework7();

In the example above we use app variable where we store Framework7 initialized instance for easy access in future. It is not necessary to name it app, it could be any name you like.

It was pretty simple. But Framework7 also provides more customization on initialization by passing object with parameters:

  1. var app = new Framework7({
  2. // App root element
  3. root: '#app',
  4. // App Name
  5. name: 'My App',
  6. // App id
  7. id: 'com.myapp.test',
  8. // Enable swipe panel
  9. panel: {
  10. swipe: 'left',
  11. },
  12. // Add default routes
  13. routes: [
  14. {
  15. path: '/about/',
  16. url: 'about.html',
  17. },
  18. ],
  19. // ... other parameters
  20. });

For list of all available app parameters check the App / Core section.

Now after we initialized our app, we need to initialize our View (<div class="view view-main"> in app layout). The View is basically the app router which is responsible for navigation:

  1. var mainView = app.views.create('.view-main');

So your final initialization code in my-app.js could look like:

  1. var app = new Framework7({
  2. // App root element
  3. root: '#app',
  4. // App Name
  5. name: 'My App',
  6. // App id
  7. id: 'com.myapp.test',
  8. // Enable swipe panel
  9. panel: {
  10. swipe: 'left',
  11. },
  12. // Add default routes
  13. routes: [
  14. {
  15. path: '/about/',
  16. url: 'about.html',
  17. },
  18. ],
  19. // ... other parameters
  20. });
  21. var mainView = app.views.create('.view-main');

What’s next

Ok, now we know how to scaffold and init the app. Now we need to check the App / Core component to learn more about its parameters and methods, how Router works, learn more about Views, Pages and the rest of the components.