New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Delayed Redirect #6422
Comments
Reference Implementationimport * as React from 'react'
import { Redirect, RedirectProps } from 'react-router'
interface DelayedProps {
delay: number
}
interface DelayedState {
timeToRedirect: boolean
}
class DelayedRedirect extends React.Component<
RedirectProps & DelayedProps,
DelayedState
> {
timeout: any = null
state: DelayedState = {
timeToRedirect: false,
}
componentDidMount() {
this.timeout = setTimeout(() => {
this.setState({
timeToRedirect: true,
})
}, this.props.delay)
}
componentWillUnmount() {
clearTimeout(this.timeout)
}
render() {
const { delay, ...props } = this.props
const { timeToRedirect } = this.state
if (timeToRedirect) {
return <Redirect {...props} />
}
return null
}
}
export default DelayedRedirect Usageimport * as React from 'react'
import { DelayedRedirect } from 'react-router-dom'
const Test = () => (
<div>
Redirect to "/" in five seconds
<DelayedRedirect to={'/'} delay={5000} />
</div>
)
export default Test |
Created a gist |
Thanks, but I don't think this is going to be something we'll build into the library. There are a number of ways you might want to build it, so it's best left up to the user to determine how they want to implement it. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Delayed Redirect
Use Case
Display a page for
n
seconds, then redirect to another page.Possible current solutions
or
The above examples require you to use a proper (non-funcitonal) component and are either verbose or imperative (both which seems to go against the latest iterations of ´react-router´).
Propsed Solution / Interface
Disclosure
I have no idea of the inner workings of
react-router
and how feasible this would be or not.The text was updated successfully, but these errors were encountered: