How to use the single-spa.navigateToUrl function in single-spa

To help you get started, we’ve selected a few single-spa examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pingcap / tidb-dashboard / ui / lib / client / index.tsx View on Github external
}
    if (errCode !== ERR_CODE_OTHER && i18next.exists(errCode)) {
      content = i18next.t(errCode)
    } else {
      content =
        response?.data?.message || err.message || i18next.t(ERR_CODE_OTHER)
    }
    err.message = content

    if (errCode === 'error.api.unauthorized') {
      // Handle unauthorized error in a unified way
      if (!routing.isLocationMatch('/') && !routing.isSignInPage()) {
        message.error({ content, key: errCode })
      }
      auth.clearAuthToken()
      singleSpa.navigateToUrl('#' + routing.signInRoute)
      err.handled = true
    } else if (errorStrategy === ErrorStrategy.Default) {
      if (method === 'get') {
        const fullUrl = config.url as string
        const API = fullUrl.replace(getBasePath(), '').split('?')[0]
        notification.error({
          key: API,
          message: i18next.t('error.title'),
          description: (
            <span>
              API: {API}
              <br>
              {content}
            </span>
          ),
        })
github CanopyTax / single-spa / spec / apis / navigate-to-url.spec.js View on Github external
it(`should call push state when the destination doesn't contain domain and has different path 1`, function() {
    singleSpa.navigateToUrl('somethinger#b/my-route');
    // If pushState wasn't called, karma will barf because the page will have reloaded if the href was changed directly
    expectPathAndHashToEqual('somethinger#b/my-route');
  });
github pingcap / tidb-dashboard / ui / lib / utils / apiClient.ts View on Github external
instance.interceptors.response.use(undefined, function (err) {
    const { response } = err
    // Handle unauthorized error in a unified way
    if (
      response &&
      response.data &&
      response.data.code === 'error.api.unauthorized'
    ) {
      if (!routing.isLocationMatch('/') && !routing.isSignInPage()) {
        message.error(i18next.t('error.message.unauthorized'))
      }
      auth.clearAuthToken()
      singleSpa.navigateToUrl('#' + routing.signInRoute)
      err.handled = true
    } else if (err.message === 'Network Error') {
      message.error(i18next.t('error.message.network'))
      err.handled = true
    }
    return Promise.reject(err)
  })
github CanopyTax / single-spa / spec / apis / navigate-to-url.spec.js View on Github external
it(`should reload the page to a new url when the origin's don't match, since that's the only way to navigate to a different domain/origin`, function() {
    const url = 'https://other-app.com/something#b/my-route';
    const opts = {isTestingEnv: true};
    const returnValue = singleSpa.navigateToUrl(url, opts);
    expect(returnValue).toEqual({wouldHaveReloadedThePage: true})
  });
github CanopyTax / single-spa / spec / apis / navigate-to-url.spec.js View on Github external
it('should update hash when destination starts with a hash', function() {
    singleSpa.navigateToUrl('#a/other');
    expect(location.hash).toBe('#a/other');
  });
github CanopyTax / single-spa / spec / apis / navigate-to-url.spec.js View on Github external
it(`should call push state when the url has no hash`, function() {
    singleSpa.navigateToUrl(hrefWithoutHash() + '/some-other-path-without-hash');
    expectPathAndHashToEqual('/some-other-path-without-hash');
  });
github pingcap / tidb-dashboard / ui / dashboardApp / layout / signin / index.tsx View on Github external
const handleSubmit = usePersistFn(async (form) => {
    try {
      clearErrorMsg()
      setLoading(true)
      const r = await client.getInstance().userLogin(fnLoginForm(form), {
        errorStrategy: ErrorStrategy.Custom,
      })
      auth.setAuthToken(r.data.token)
      message.success(t('signin.message.success'))
      singleSpa.navigateToUrl(successRoute)
    } catch (e) {
      if (!e.handled) {
        setError(t('signin.message.error', { msg: e.message }))
        onFailure()
      }
    } finally {
      setLoading(false)
    }
  })
github pingcap / tidb-dashboard / ui / dashboardApp / index.ts View on Github external
registry
    .register(AppDebugPlayground)
    .register(AppDashboardSettings)
    .register(AppUserProfile)
    .register(AppOverview)
    .register(AppKeyViz)
    .register(AppStatement)
    .register(AppClusterInfo)
    .register(AppDiagnose)
    .register(AppSearchLogs)
    .register(AppInstanceProfiling)
    .register(AppSlowQuery)

  if (routing.isLocationMatch('/')) {
    singleSpa.navigateToUrl('#' + registry.getDefaultRouter())
  }

  window.addEventListener('single-spa:app-change', () => {
    const spinner = document.getElementById('dashboard_page_spinner')
    if (spinner) {
      spinner.remove()
    }
    if (!routing.isSignInPage()) {
      if (!auth.getAuthTokenAsBearer()) {
        singleSpa.navigateToUrl('#' + routing.signInRoute)
      }
    }
  })

  window.addEventListener('single-spa:before-routing-event', () => {})
github pingcap / tidb-dashboard / ui / dashboardApp / index.ts View on Github external
window.addEventListener('single-spa:app-change', () => {
    const spinner = document.getElementById('dashboard_page_spinner')
    if (spinner) {
      spinner.remove()
    }
    if (!routing.isSignInPage()) {
      if (!auth.getAuthTokenAsBearer()) {
        singleSpa.navigateToUrl('#' + routing.signInRoute)
      }
    }
  })