当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript IRouter.navigate方法代码示例

本文整理汇总了TypeScript中@jupyterlab/application.IRouter.navigate方法的典型用法代码示例。如果您正苦于以下问题:TypeScript IRouter.navigate方法的具体用法?TypeScript IRouter.navigate怎么用?TypeScript IRouter.navigate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@jupyterlab/application.IRouter的用法示例。


在下文中一共展示了IRouter.navigate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: redirect

  export async function redirect(
    router: IRouter,
    paths: JupyterFrontEnd.IPaths,
    workspace: string,
    warn = false
  ): Promise<void> {
    const form = createRedirectForm(warn);
    const dialog = new Dialog({
      title: 'Please use a different workspace.',
      body: form,
      focusNodeSelector: 'input',
      buttons: [Dialog.okButton({ label: 'Switch Workspace' })]
    });
    const result = await dialog.launch();

    dialog.dispose();
    if (!result.value) {
      return redirect(router, paths, workspace, true);
    }

    // Navigate to a new workspace URL and abandon this session altogether.
    const page = paths.urls.page;
    const workspaces = paths.urls.workspaces;
    const prefix = (workspace ? workspaces : page).length + workspace.length;
    const rest = router.current.request.substring(prefix);
    const url = URLExt.join(workspaces, result.value, rest);

    router.navigate(url, { hard: true, silent: true });

    // This promise will never resolve because the application navigates
    // away to a new location. It only exists to satisfy the return type
    // of the `redirect` function.
    return new Promise<void>(() => undefined);
  }
开发者ID:afshin,项目名称:jupyterlab,代码行数:34,代码来源:index.ts

示例2: redirect

  export async function redirect(router: IRouter, warn = false): Promise<void> {
    const form = createRedirectForm(warn);
    const dialog = new Dialog({
      title: 'Please use a different workspace.',
      body: form,
      focusNodeSelector: 'input',
      buttons: [Dialog.okButton({ label: 'Switch Workspace' })]
    });

    const result = await dialog.launch();

    dialog.dispose();
    if (!result.value) {
      return redirect(router, true);
    }

    // Navigate to a new workspace URL and abandon this session altogether.
    const workspaces = PageConfig.getOption('workspacesUrl');
    const url = URLExt.join(workspaces, result.value);

    router.navigate(url, { hard: true, silent: true });

    // This promise will never resolve because the application navigates
    // away to a new location. It only exists to satisfy the return type
    // of the `redirect` function.
    return new Promise<void>(() => undefined);
  }
开发者ID:willingc,项目名称:jupyterlab,代码行数:27,代码来源:index.ts

示例3: async

  activate: async (
    _: JupyterFrontEnd,
    paths: JupyterFrontEnd.IPaths,
    router: IRouter
  ) => {
    const { hash, path, search } = router.current;
    const query = URLExt.queryStringToObject(search || '');
    const solver = new WindowResolver();
    const match = path.match(new RegExp(`^${paths.urls.workspaces}([^?\/]+)`));
    const workspace = (match && decodeURIComponent(match[1])) || '';
    const candidate = Private.candidate(paths, workspace);

    try {
      await solver.resolve(candidate);
    } catch (error) {
      // Window resolution has failed so the URL must change. Return a promise
      // that never resolves to prevent the application from loading plugins
      // that rely on `IWindowResolver`.
      return new Promise<IWindowResolver>(() => {
        // If the user has requested workspace resolution create a new one.
        if (WORKSPACE_RESOLVE in query) {
          const { base, workspaces } = paths.urls;
          const pool =
            'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
          const random = pool[Math.floor(Math.random() * pool.length)];
          const path = URLExt.join(base, workspaces, `auto-${random}`);

          // Clone the originally requested workspace after redirecting.
          query['clone'] = workspace;

          // Change the URL and trigger a hard reload to re-route.
          const url = path + URLExt.objectToQueryString(query) + (hash || '');
          router.navigate(url, { hard: true, silent: true });
          return;
        }

        // Launch a dialog to ask the user for a new workspace name.
        console.warn('Window resolution failed:', error);
        return Private.redirect(router, paths, workspace);
      });
    }

    // If the user has requested workspace resolution remove the query param.
    if (WORKSPACE_RESOLVE in query) {
      delete query[WORKSPACE_RESOLVE];

      // Silently scrub the URL.
      const url = path + URLExt.objectToQueryString(query) + (hash || '');
      router.navigate(url, { silent: true });
    }

    return solver;
  }
开发者ID:afshin,项目名称:jupyterlab,代码行数:53,代码来源:index.ts

示例4:

      return new Promise<IWindowResolver>(() => {
        const { base, workspaces } = paths.urls;
        const pool =
          'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        const random = pool[Math.floor(Math.random() * pool.length)];
        const path = URLExt.join(base, workspaces, `auto-${random}`) + rest;

        // Clone the originally requested workspace after redirecting.
        query['clone'] = workspace;

        // Change the URL and trigger a hard reload to re-route.
        const url = path + URLExt.objectToQueryString(query) + (hash || '');
        router.navigate(url, { hard: true, silent: true });
      });
开发者ID:jupyter,项目名称:jupyterlab,代码行数:14,代码来源:index.ts

示例5: redirect

    return dialog.launch().then(result => {
      dialog.dispose();

      if (result.value) {
        const url = `workspaces/${result.value}`;

        // Navigate to a new workspace URL and abandon this session altogether.
        router.navigate(url, { hard: true, silent: true });

        // This promise will never resolve because the application navigates
        // away to a new location. It only exists to satisfy the return type
        // of the `redirect` function.
        return new Promise<void>(() => { /* no-op */ });
      }

      return redirect(router, true);
    });
开发者ID:groutr,项目名称:jupyterlab,代码行数:17,代码来源:index.ts

示例6: showDialog

  activate: (app: JupyterLab, router: IRouter) => {
    const bad = PageConfig.getOption('notFoundUrl');
    const base = router.base;

    if (!bad) {
      return;
    }

    // Change the URL back to the base application URL without adding the
    // URL change to the browser history.
    router.navigate('', { silent: true });

    showDialog({
      title: 'Path Not Found',
      body: `The path: ${bad} was not found. JupyterLab redirected to: ${base}`,
      buttons: [Dialog.okButton()]
    });
  },
开发者ID:7125messi,项目名称:jupyterlab,代码行数:18,代码来源:index.ts

示例7:

      return new Promise<IWindowResolver>(() => {
        // If the user has requested workspace resolution create a new one.
        if (WORKSPACE_RESOLVE in query) {
          const { base, workspaces } = paths.urls;
          const pool =
            'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
          const random = pool[Math.floor(Math.random() * pool.length)];
          const path = URLExt.join(base, workspaces, `auto-${random}`);

          // Clone the originally requested workspace after redirecting.
          query['clone'] = workspace;

          // Change the URL and trigger a hard reload to re-route.
          const url = path + URLExt.objectToQueryString(query) + (hash || '');
          router.navigate(url, { hard: true, silent: true });
          return;
        }

        // Launch a dialog to ask the user for a new workspace name.
        console.warn('Window resolution failed:', error);
        return Private.redirect(router, paths, workspace);
      });
开发者ID:afshin,项目名称:jupyterlab,代码行数:22,代码来源:index.ts

示例8:

 cleared.then(() => {
   router.navigate(url, { silent });
   loading.dispose();
 });
开发者ID:willingc,项目名称:jupyterlab,代码行数:4,代码来源:index.ts


注:本文中的@jupyterlab/application.IRouter.navigate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。