{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# `ui.navigate`\n", "\n", "## 导航函数\n", "\n", "这些函数允许您在浏览器历史中进行导航,并跳转到外部URL。" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from nicegui import ui\n", "\n", "with ui.row():\n", " ui.button('Back', on_click=ui.navigate.back)\n", " ui.button('Forward', on_click=ui.navigate.forward)\n", " ui.button(icon='savings',\n", " on_click=lambda: ui.navigate.to('https://github.com/sponsors/zauberzeug'))\n", "\n", "# ui.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## `ui.navigate.to`\n", "\n", "可用于以编程方式打开不同的页面或URL。\n", "\n", "当使用 `new_tab` 参数时,浏览器可能会阻止新标签页的打开。这是浏览器设置,应用程序无法更改。您可能希望改用 `ui.link` 及其 `new_tab` 参数。\n", "\n", "此功能以前作为 `ui.open` 提供,现已弃用。\n", "\n", "注意:当使用自动索引页面(例如没有 `@page` 装饰器)时,除非指定了套接字,否则连接到该页面的所有客户端(即浏览器)都将打开目标 URL。用户事件(如按钮点击)提供了这样的套接字。\n", "\n", "- `target`:页面函数、同一页面上的NiceGUI元素或从基本URL开始的绝对URL或相对路径的字符串\n", "- `new_tab`:是否在新标签页中打开目标(可能会被浏览器阻止)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from nicegui import ui\n", "\n", "url = 'https://github.com/zauberzeug/nicegui/'\n", "ui.button('Open GitHub', on_click=lambda: ui.navigate.to(url, new_tab=True))\n", "\n", "# ui.run()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "py311", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.7" } }, "nbformat": 4, "nbformat_minor": 2 }