How to force my app to reload itself with new query params?

I’ve figured it out.
In the start file that launches the application, all modules for your project must be imported.
And also, if this suddenly does not help, you can do it manually using the button:

from pages import home, page1, page2

...


def reload_click(event):
    for module_name in list(sys.modules.keys()):
        if module_name.startswith('pages.'):
            print(module_name)
            importlib.reload(sys.modules[module_name])

    # Reload the current page
    current_page = pn.state.location.query_params.get('page')
    pn.state.location.param.update(search=f"?page={current_page}")

    pn.state.location.reload = False
    pn.state.location.reload = True

reload_button = pn.widgets.Button(name='Reload', on_click=reload_click)

And modules, which are in folder page, reloading fine

1 Like