Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #101670
    Dark Beccio
    Member

    Hi, when loading sub pages from my smart.router path list javascript is loaded only the first time, second time i go in that page i get only html.
    Problem is i can not use window.onload on sub pages.
    Is there any other event i can use?
    if not , what is the correct way to build router sub pages ?

    #101678
    yavordashew
    Member

    Hi Dark Beccio,
    Take my apologies for the late reply.
    You can use the templateApplied setting of the Smart.Router and with it you can run the javascript each time the template is applied.
    I have made a little code snippet on how to achieve this:
    //In your JS file

    
    window.onload = function () {
        const router = new JQX.Router('mainView', './');
        router.setRoutes([
            { path: '/', template: 'homeTemplate', title: 'Home' },
            { path: '/about', template: 'aboutTemplate', title: 'About',},
            { path: '/contacts', template: 'contactsTemplate', title: 'Contacts' }
        ]);
        router.templateApplied = viewChanged;
        function viewChanged(route) {
        const path = route.path;
            if (path == '/about'){
                alert('The route is: '+ path)
            }
        }
        router.route('/');
    };

    Note that for base for this code snippet I have used the example from the documentation about the Router.
    Here is a link for it: https://www.htmlelements.com/docs/router/
    Please, do not hesitate to contact us if you have any additional questions.
    Best regards,
    Yavor Dashev
    Smart UI Team
    https://www.htmlelements.com/

    #101681
    Dark Beccio
    Member

    Don’t worry, i made consulting with u’r  <span lang=”en”>Colleagues and we solved the problems =)</span>

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.