Router .add('auth', function () { pageActive(''); Auth.init();; }) .add('territory/manager/(.*)/(.*)', function (type, id) { pageActive(); Territory_Manager.init(type, id); }) .add('territory/editor/(.*)/(.*)', function (type, id) { pageActive(); Editor.init(type, id); }) .add('territory/card/(.*)/(.*)', function (type, id) { pageActive(); Card.init(type, id); }) .add('territory', function () { pageActive('territory'); Territory.init(); }) .add('sheeps/(.*)', function (name) { pageActive('sheeps'); Sheeps.init(name);; }) .add('sheeps', function () { pageActive('sheeps'); Sheeps.init();; }) .add('home', function () { pageActive('home'); Home.init(); }) .add('schedule', function () { pageActive('schedule'); Schedule.init();; }) .add('stand', function () { pageActive('stand'); Stand.init();; }) .add('options', function () { pageActive('options'); Options.init();; }) .add('constructor', function () { pageActive(); Constructor.init();; }) .add(function () { page_404();; pageActive(); }) function pageActive(element) { const active = document.querySelector("nav li [data-state='active']"); if (active) active.setAttribute('data-state', ''); if (element) { const target = document.getElementById(`nav-${element}`); if (target) target.setAttribute('data-state', 'active'); } }