# ui.navigate | NiceGUI

[Button: icon:menu]

[](/zh)

[安装](/zh#installation)

[特性](/zh#features)

[演示](/zh#demos)

[文档](/zh/documentation)

[示例](/zh/examples)

[为什么？](/zh#why)

[Button]

[Button]

[Button]

[](https://github.com/zauberzeug/nicegui/)

[Button: icon:more_vert]

# ui.*navigate*

## Navigation functions

These functions allow you to navigate within the browser history and to external URLs.

*Added in version 2.0.0*

main.py

[Button]

````python
from nicegui import ui

with ui.row():
    ui.button('Back', on_click=ui.navigate.back)
    ui.button('Forward', on_click=ui.navigate.forward)
    ui.button('Reload', on_click=ui.navigate.reload)
    ui.button(icon='savings',
              on_click=lambda: ui.navigate.to('https://github.com/sponsors/zauberzeug'))

ui.run()
````

## ui.navigate.to (formerly ui.open)

Can be used to programmatically open a different page or URL.

When using the `new_tab` parameter, the browser might block the new tab.
This is a browser setting and cannot be changed by the application.
You might want to use `ui.link` and its `new_tab` parameter instead.

:target: page function, NiceGUI element on the same page or string that is a an absolute URL or relative path from base URL
:new_tab: whether to open the target in a new tab (might be blocked by the browser)

main.py

[Button]

````python
from nicegui import ui

url = 'https://github.com/zauberzeug/nicegui/'
ui.button('Open GitHub', on_click=lambda: ui.navigate.to(url, new_tab=True))

ui.run()
````

## Push and replace URLs

The `history` API allows you to push and replace URLs to the browser history.

While the `history.push` method pushes a new URL to the history,
the `history.replace` method replaces the current URL.

See [JavaScript's History API](https://developer.mozilla.org/en-US/docs/Web/API/History) for more information.

*Added in version 2.13.0*

main.py

[Button]

````python
from nicegui import ui

ui.button('Push URL', on_click=lambda: ui.navigate.history.push('/a'))
ui.button('Replace URL', on_click=lambda: ui.navigate.history.replace('/b'))

ui.run()
````

**Nice**GUI

在浏览器中呈现的 Python UI 框架。

[](https://github.com/zauberzeug/nicegui/)

[](https://discord.gg/TEpFeAaF4f)

[](https://www.reddit.com/r/nicegui/)

资源

[文档](/zh/documentation)

[示例](/zh/examples)

[LLM 参考](/llms.txt)

[GitHub](https://github.com/zauberzeug/nicegui/)

[PyPI](https://pypi.org/project/nicegui/)

社区

[讨论区](https://github.com/zauberzeug/nicegui/discussions)

[Discord](https://discord.gg/TEpFeAaF4f)

[Reddit](https://www.reddit.com/r/nicegui/)

[参与贡献](https://github.com/zauberzeug/nicegui/blob/main/CONTRIBUTING.md)

[赞助者](https://github.com/sponsors/zauberzeug)

法律

[法律声明](/zh/imprint_privacy#imprint)

[隐私](/zh/imprint_privacy#privacy)

由 [Zauberzeug](https://zauberzeug.com) 用 NiceGUI 打造

© 2026 [Zauberzeug GmbH](https://zauberzeug.com)