How to use the next/router.replace function in next

To help you get started, we’ve selected a few next 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 statico / aspen / pages / index.js View on Github external
this.setState({ results: null })
      return
    }

    try {
      this.setState({ inProgress: true, results: null })

      const queryString = qs.stringify({
        query,
        page: page && page > 0 ? page + 1 : undefined,
        sloppy: sloppy ? 1 : undefined
      })

      // If we're typing fast, don't add incomplete queries to browser history.
      if (this.inFlightRequest) {
        Router.replace('/?' + queryString)
      } else {
        Router.push('/?' + queryString)
      }

      if (this.inFlightRequest) this.inFlightRequest.abort()
      const req = this.inFlightRequest = request.get(getOrigin() + '/search').query(queryString).withCredentials()
      const response = await req
      const obj = response.body

      if (obj.error) {
        // Elasticsearch will complain about broken queries, like '"foo' (missing a double quote)
        if (/QueryParsingException/.test(obj.error)) {
          obj.error = <span>
            That search query looks incomplete. Please see the {' '}
            <a href="https://www.elastic.co/guide/en/elasticsearch/reference/1.7/query-dsl-query-string-query.html#query-string-syntax">Elasticsearch 1.7 query string documentation</a>.
          </span>
github kunalgorithm / graphql-fullstack / components / lib / auth.tsx View on Github external
export const redirect = (context, target) => {
  if (context.res) {
    // server
    // 303: "See other"
    context.res.writeHead(303, { Location: target });
    context.res.end();
  } else {
    // In the browser, we just pretend like this never even happened ;)
    Router.replace(target);
  }
};
github voluntarily / vly2 / pages / act / actdetailpage.js View on Github external
async handleDelete (act) {
    if (!act) return
    // Actual data request
    await this.props.dispatch(reduxApi.actions.activities.delete({ id: act._id }))
    // TODO error handling - how can this fail?
    message.success('Deleted. ')
    Router.replace(`/acts`)
  }
github Enalmada / next-reason-boilerplate / util / redirect.js View on Github external
export default (context, target, code = 303) => {
    if (context.res || !process.browser) {
        // server
        // 303: "See other"
        context.res.writeHead(code, {Location: target});
        context.res.end();
    } else {
        // In the browser, we just pretend like this never even happened ;)
        Router.replace(target);
    }
};
github pythonkr / pyconkr-web / pages / account / login.tsx View on Github external
async componentDidMount() {
    const { stores } = this.props
    stores.authStore.syncToken()

    if (stores.authStore.loggedIn) {
      Router.replace(this.props.router!.query.redirect_url)

      return
    }
  }
github minooo / react-ssr / pages / 1-loan / 3-goLoan.js View on Github external
componentWillMount() {
    if (this.props.err) {
      Router.replace({ pathname: '/3-me/2-login', query: { href: '/1-loan/3-goLoan', as: '/loan/go' } }, '/login')
    }
  }
  componentDidMount() {
github belaczek / hodlwatch / src / components / Redirect / index.js View on Github external
componentDidMount () {
    const { to, as, options, replace } = this.props
    if (to) {
      if (replace) {
        Router.replace(to, as, options)
      } else {
        Router.push(to, as, options)
      }
    }
  }
github NoQuarterTeam / fullstack-boilerplate / packages / ssr / src / pages / Login.tsx View on Github external
      .then(() => Router.replace("/dashboard"))
      .catch((error: GraphQLError) => {
github veteransaffairscanada / vac-benefits-directory / components / edit_selections_modal.js View on Github external
clearQueryParams = () => {
    const newUrl = this.props.url;
    this.props.profileQuestions.forEach(q => {
      newUrl.query[q.variable_name] = "";
    });
    newUrl.query["selectedNeeds"] = {};
    Router.replace(mutateUrl(newUrl, "", ""));
  };