Page

    Page is one of the main components (containers) used to display app content.

    Page Layout

    <div class="page" data-name="home">
      <div class="page-content">
        ... scrollable page content goes here ...
      </div>
    </div>

    Page Name

    As you may note each page has data-name attribute with unique page name. It is not required but can be useful within "page events" or within "page callbacks" and help us to define which page is loaded to make required manipulations.

    Page Content

    All visual content (like list views, forms, etc.) we should put inside of <div class="page-content"> that should be a child of <div class="page">. It is required for correct styling, layout and scrolling

    Page Events

    Now, let's look at one of the most important part of page navigation - page events. These events allow us to manipulate just loaded pages by executing JavaScript for specific pages:

    Event Target Description
    page:mounted Page Element<div class="page"> Event will be triggered when new page just inserted to DOM
    page:init Page Element<div class="page"> Event will be triggered after Framework7 initialize required page's components and navbar
    page:reinit Page Element<div class="page"> This event will be triggered in case of navigating to the page that was already initialized.
    page:beforein Page Element<div class="page"> Event will be triggered when everything initialized and page is ready to be transitioned into view (into active/current position)
    page:afterin Page Element<div class="page"> Event will be triggered after page transitioned into view
    page:beforeout Page Element<div class="page"> Event will be triggered right before page is going to be transitioned out of view
    page:afterout Page Element<div class="page"> Event will be triggered after page transitioned out of view
    page:beforeremove Page Element<div class="page"> Event will be triggered right before Page will be removed from DOM. This event could be very useful if you need to detach some events / destroy some plugins to free memory

    Let's see how we can use these events. There are two ways to add page events handler:

    // Option 1. Using one 'page:init' handler for all pages
    $$(document).on('page:init', function (e) {
      // Do something here when page loaded and initialized
    })
    
    // Option 2. Using live 'page:init' event handlers for each page
    $$(document).on('page:init', '.page[data-name="about"]', function (e) {
      // Do something here when page with data-name="about" attribute loaded and initialized
    })

    Page Loading Sequence Classes

    When new pages is loading and transitioned to the view (main visible part of the) it has different classes on page element.

    When we load/open new page the following happens:

    1. Currently active page has page-current class.
    2. If page we load not in DOM (e.g. loaded via Ajax or using template or from component) it will be added to DOM.
    3. Page that we load/open will have additional page-next class set on its element.
    4. Router element (<div class="view">) will have additional router-transition-forward class that does the following:
      • page with page-next (new page) class moves into the view
      • page with page-current (current page) class moves out of the view
    5. After transition completed, the new page that we loaded will have page-current class
    6. And the page that was previously active will have page-previous class

    When we load/open previous page (go back) the following happens:

    1. Currently active page has page-current class.
    2. If page we go back to not in DOM (e.g. loaded via Ajax or using template or from component) it will be added to DOM.
    3. Page that we go back to will have additional page-previous class set on its element.
    4. Router element (<div class="view">) will have additional router-transition-backward class that does the following:
      • page with page-previos (page that we go back to) class moves into the view
      • page with page-current (current page) class moves out of the view
    5. After transition completed, the new page that we returned to will have page-current class
    6. And the page that was previously active will have page-next class. In case this page was added to DOM dynamically, it will be removed from DOM.

    Page Data

    As you may see it is pretty easy, but hey, how to determine which page is loaded in first option when we use only one handler? For this case we have Page Dage in event details:

    // In page events:
    $$(document).on('page:init', function (e) {
      // Page Data contains all required information about loaded and initialized page
      var page = e.detail;
    })

    Or in case the event handler was assigned using Dom7 like in example above then it will be passed in second argument:

    // In page events:
    $$(document).on('page:init', function (e, page) {
      console.log(page);
    })

    Now, in the example above we have page data in page variable. It is an object with the following properties:

    page.app object Initialized app instance
    page.view object View instance that contains this page (if this View was initialized)
    page.router object Router instance that contains this page (if this View was initialized). Same as page.view.router
    page.app string Initialized app instance
    page.name string Value of page's data-name attribute
    page.el HTMLElement Page element
    page.$el object Dom7 instance with Page element
    page.navbarEl HTMLElement Related navbar element for this page. Available only in iOS theme with dynamic navbar enabled.
    page.$navbarEl object Dom7 instance with related navbar element for this page. Available only in iOS theme with dynamic navbar enabled.
    page.from string Page position before transition or direction of where this Page comes from. It will be next if you load new page, previous - if you go back to this page, or current if this page replaces the currently active one.
    page.to string New page position or where this page goes to. Can be same next, previous or current
    page.position string Alias for page.from
    page.direction string Direction of page transition (if applicable). Can be forward or backward
    page.route object Route associated with this page
    page.pageFrom object Page data of the page that was currently active before this new page.
    page.context object Template7 context that was passed for this page when using Template7 pages
    page.fromPage object Page Data object of the previously active page

    Access To Page Data

    If you don't use page events/callbacks and need to access page data it is possible via f7Page property on its HTMLElement:

    var $$ = Dom7;
    
    var page = $$('.page[data-name="somepage"]')[0].f7Page;
    
    // do something with page data