How to use the next/router.useRouter 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 zeit / next.js / test / integration / dynamic-routing / pages / blog / [name] / comment / [id].js View on Github external
const Page = () => {
  const router = useRouter()
  const { name, id } = router.query

  return (
    <>
      <p>
        Blog post {name} comment {id || '(all)'}
      </p>
    
  )
}
github zeit / next.js / test / integration / dynamic-routing / pages / [name] / [comment].js View on Github external
const $comment = ({ gipQuery }) =&gt; {
  const router = useRouter()
  const { query } = router

  return (
    &lt;&gt;
      <p>
        I am {query.comment} on {query.name}
      </p>
      <span>gip {gipQuery &amp;&amp; gipQuery.name}</span>
    
  )
}
github startups-services / epic-admin-dashboard / components / Forms / CreateProject.js View on Github external
const CreateProject = () => {
  const router = useRouter();
  const dispatch = useDispatch();
  const [name, setName] = useState('');
  const [subLabel, setSubLabel] = useState('');
  const [costs, setCosts] = useState('');
  const [tags, setTags] = useState([]);
  const [description, setDescription] = useState('');
  const [users, setUsers] = useState([]);
  const [startDate, setStartDate] = useState(new Date());
  const [dueDate, setDueDate] = useState(new Date());

  console.log(users);
  const addAssignee = (val) => {
    setUsers(((prevState) => ([...prevState, val.user])));
  };

  const removeAssignee = (val) => {
github data-driven-forms / react-forms / packages / react-renderer-demo / src / app / pages / component-example.js View on Github external
export default () =&gt; {
  const router = useRouter();
  return (
    
      { ({ loaded, mappers }) =&gt;
        loaded &amp;&amp;  }
    
  );
};
github VincentCordobes / the-green-meal / client / login-form.tsx View on Github external
const LoginForm: React.FC = props =&gt; {
  const router = useRouter()

  const [apiError, setApiError] = useState()
  const [loading, setLoading] = useState(false)

  const handleSubmit = (e: React.FormEvent) =&gt; {
    e.preventDefault()
    props.form.validateFields((err, body) =&gt; {
      if (!err) {
        setLoading(true)
        request("/api/auth", {method: "POST", body}).then(
          response =&gt; {
            if (response.ok) {
              cookie.set("token", response.value.token, {expires: 7})
              router.replace("/")
            } else {
              setLoading(false)
github zmj0920 / next-github / pages / detail / index.js View on Github external
const Detail = ({ readme }) =&gt; {

  const router = useRouter()

  //根据路由缓存
  useCache(genDetailCacheKey(router), {
    readme
  })

  return (
    
  )
}
github MacKentoch / react-redux-nextjs-bootstrap-pwa-starter / components / privateRoute / PrivateRoute.js View on Github external
function Private({ fromPath = '/', children }: Props) {
  const { replace } = useRouter();

  useEffect(() => {
    const userIsAuthenticated = checkIsAuthenticated();
    const userTokenExpired = checkIsExpired();
    const RoutePayload = {
      pathname: '/login',
      query: { from: fromPath },
    };

    if (!userIsAuthenticated) {
      replace(RoutePayload);
    }

    if (userTokenExpired) {
      replace(RoutePayload);
    }
github pradel / sigle / src / modules / publicHome / components / PublicHome.tsx View on Github external
export const PublicHome = ({ file }: PublicHomeProps) =&gt; {
  const router = useRouter();
  const { username } = router.query as { username: string };

  return (
    
      <header>
        
          {username}
          
            Stories
          
        
      </header>
      
        {file.stories.length === 0 &amp;&amp; No stories yet}
        {file.stories.map(story =&gt; (
github conveyal / analysis-ui / lib / components / create-project.js View on Github external
export default React.memo(function ConnectedCreateProject(p) {
  const dispatch = useDispatch()
  const router = useRouter()

  return 
})
github pradel / sigle / src / modules / auth / Protected.tsx View on Github external
export const Protected = ({ children }: Props) => {
  const router = useRouter();
  const [state, setState] = useState({
    loggedIn: config.isServer ? false : !!userSession.isUserSignedIn(),
    loggingIn: config.isServer ? true : !!userSession.isSignInPending(),
  });

  useEffect(() => {
    if (userSession.isUserSignedIn() && !state.loggedIn) {
      setState({
        loggedIn: true,
        loggingIn: false,
      });
    } else if (userSession.isSignInPending()) {
      userSession
        .handlePendingSignIn()
        .then(() => {
          setState({