Monaca Onsen UI Discord Chat Github Repo

How to add #hash for the urls / pushState



  • I am new in this framework - looks great!

    When i go to page2.html i want #hash (

    index.html#page2
    

    I don’t find this idea in the docs (Framework7 for example call this pushState).

    Thanks.


  • administrators

    There’s no support for URLs built in to Onsen UI but you can add it quite easily:

    document.querySelector('#myNavigator')
        .pushPage('page2.html', {data: {hash: 'page2'}})
        .then((page) => {
          window.location.hash = page.data.hash;
        });
    

    (Note: I haven’t actually tested the line that sets the hash in this example but something like this should work.)