Initialize App

After we have our app layout now we need to mount React 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.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 Create React App, Webpack or Browserify, you might typically have a root-level app.js or index.js file that mounts your root app component:

  1. // app.js
  2. // Import React
  3. import React from 'react';
  4. // Import ReactDOM
  5. import ReactDOM from 'react-dom';
  6. // Import F7 Bundle
  7. import Framework7 from 'framework7/framework7.esm.bundle.js';
  8. // Import F7-React Plugin
  9. import Framework7React from 'framework7-react';
  10. // Init F7-React Plugin
  11. Framework7.use(Framework7React);
  12. // Import Main App component
  13. import App from './App.jsx';
  14. // Mount React App
  15. ReactDOM.render(
  16. React.createElement(App),
  17. document.getElementById('app')
  18. )

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

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

In the examples above:

  • we pass Framework7 parameters to the App main Framework7 app component in its **params** property;
  • root element passed to ReactDOM.render (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 React Component Extensions, router and routes in the Navigation Router section.