JavaScript UI Libraries & Blazor Components Suite – Smart UI › Forums › General Discussions › how use routing correctly › Reply To: how use routing correctly
March 31, 2021 at 2:23 pm
#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/