How to use the next/router.push 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 zprima / jwt-cors-app / app / utils / auth.js View on Github external
try {
    const response = await axios.get(serverUrl + "/api/token/ping", { headers: { 'Authorization': token } });
    // dont really care about response, as long as it not an error
    console.log("token ping:", response.data.msg)
  } catch (err) {
    // in case of error
    console.log(err.response.data.msg);
    console.log("redirecting back to main page");
    // redirect to login
    if (ctx.res) {
      ctx.res.writeHead(302, {
        Location: '/'
      })
      ctx.res.end()
    } else {
      Router.push('/')
    }
  }
}
github Dexecure / ruxt / components / resultGraph.js View on Github external
handleOnURLChange(event, { newValue }) {
    const originUrl = { newValue };
    this.setState({
      url: originUrl.newValue
    });

    // update the url
    const { query } = Router;
    query[`url${this.props.id}`] = originUrl.newValue;
    const newURL = `${window.location.pathname}?${qs.stringify(query, {
      encode: false
    })}`;
    Router.push(newURL, newURL, { shallow: true });
  }
github geovanisouza92 / serverless-next / pages / login.js View on Github external
.then(res => {
        if (res.error) {
          this.setState(
            prevState => ({ ...prevState, isLoading: false, error: res.error })
          )
          return
        }

        // Redirect
        if (this.state.returnUrl) {
          Router.push(this.state.returnUrl)
        } else {
          Router.push('/')
        }
      })
  }
github orbiting / republik-frontend / components / Testimonial / Image.js View on Github external
next() {
    const { statement, query, error } = this.props
    if (error && !query.sequenceNumber) {
      console.error(error)
      return
    }
    const to = {
      pathname: '/community',
      query: {
        ...query,
        sequenceNumber: error
          ? undefined
          : statement && statement.sequenceNumber
      }
    }
    Router.push(to, to, { shallow: true })
  }
  componentDidMount() {
github dpla / dpla-frontend / components / SearchComponents / MainContent / Sidebar / index.js View on Github external
handleDateSubmit(e) {
    e.preventDefault();
    const dateProps = this.getDateProps();
    Router.push({
      pathname: this.props.route.pathname,
      query: Object.assign(
        {},
        removeQueryParams(this.props.route.query, ["after", "before"]),
        dateProps,
        {
          page: 1
        }
      )
    });
  }
github coderplex / linklet-app / utils / redirect.js View on Github external
export default (
  ctx,
  to = `/profile?next=${encodeURIComponent(
    ctx.req ? ctx.req.url : ctx.pathname
  )}`
) => {
  console.log(ctx)
  if (ctx.res) {
    ctx.res.writeHead && ctx.res.writeHead(302, { Location: to })
    ctx.res.end && ctx.res.end()
    return {}
  } else {
    return Router.push(to)
  }
}
github rubygarage / nextjs6-graphql-client-tutorial / containers / GithubLoginButtonContainer / index.js View on Github external
handleSignOut = () => {
    Cookies.remove('access_token');
    Router.push('/');
  };
github async-labs / saas / app / pages / settings / index.tsx View on Github external
logout = () => {
    Router.push(`${LOG_OUT_URL}/logout`);
  };
github CheesecakeLabs / react-next-boilerplate / src / pages / signin / index.js View on Github external
.then(({ data, error }) => {
        if (!error) {
          this.storeToken(data.token)
          this.setState(() => ({
            loggedUser: data,
            token: data.token,
            loginError: error,
            authenticated: data.token ? true : false,
          }))
          Router.push('/')
        } else {
          this.setState(() => ({
            loginError: error.non_field_errors,
          }))
        }
      })
  }
github ritoplz / ritoplz / pages / logout.js View on Github external
componentDidMount() {
    logout()
    Router.push('/')
  }