10 examples of 'react redirect to external url onclick' in JavaScript

Every line of 'react redirect to external url onclick' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
68function redirect(text = null) {
69 if (text == null) {
70 text = document.querySelector('#search-box').value;
71 }
72 location.href = '/?q=' + encodeURIComponent(text);
73}
Important

Use secure code every time

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

73function redirectLinkClicked() {
74 var link = jQuery('#secureLinkWithRedirectId');
75 var extraData = link.attr('id') + '=1';
76 var url = link.attr('href');
77 jQuery.get(url, extraData, function(data, textStatus, xhr) {
78 // Retrieve the url to redirect from the Ajax response header
79 var redirect_url = xhr.getResponseHeader('REDIRECT_URL');
80 // Perform the redirect
81 window.location = redirect_url;
82
83 });
84}
19handleRedirect() {
20 const { location, history, currentUser, ready } = this.props;
21 const { state: routerState = {}, ...locationWithoutState } = location;
22 const allowedAccessLevels = ['reporting', 'heroku', 'azure', 'marketing'];
23
24 // if there is a redirect route set on state, we can
25 // redirect there before access condition state is ready
26 if (routerState.redirectAfterLogin) {
27 history.replace({ ...locationWithoutState, ...routerState.redirectAfterLogin });
28 return;
29 }
30
31 // if access condition state hasn't loaded, we can't
32 // make a redirect decision yet
33 if (!ready) {
34 return;
35 }
36
37 // reporting users are all sent to the summary report
38 if (_.includes(allowedAccessLevels, currentUser.access_level)) {
39 history.replace({ ...location, pathname: '/reports/summary' });
40 return;
41 }
42
43 // everyone else is sent to the config.splashPage route
44 history.replace({ ...location, pathname: config.splashPage });
45}
50function redirect()
51{
52if (second < 0)
53{
54 <!--定义倒计时后跳转页面-->
55location.href = '/sba';
56} else
57{
58if (navigator.appName.indexOf("Explorer") > -1)
59{
60document.getElementById('totalSecond').innerText = second--;
61} else
62{
63document.getElementById('totalSecond').textContent = second--;
64}
65}
66}
86function Redirect({panes}) {
87 const router = useRouter()
88
89 useEffect(() => {
90 router.navigate({panes}, {replace: true})
91 })
92
93 return <Spinner center message="Redirecting…" delay={600} />
94}
76export function redirect( context ) {
77 const state = context.store.getState();
78 const siteId = getSelectedSiteId( state );
79 if ( siteId ) {
80 page.redirect( '/activity-log/' + siteId );
81 return;
82 }
83 page.redirect( '/activity-log/' );
84}
43linkClicked (e) {
44 if (e.currentTarget.nodeName === 'A' &&
45 (e.metaKey || e.ctrlKey || e.shiftKey || (e.nativeEvent && e.nativeEvent.which === 2))) {
46 // ignore click for new tab / new window behavior
47 return
48 }
49
50 const { shallow } = this.props
51 let { href, as } = this
52
53 if (!isLocal(href)) {
54 // ignore click if it's outside our scope
55 return
56 }
57
58 const { pathname } = window.location
59 href = resolve(pathname, href)
60 as = as ? resolve(pathname, as) : href
61
62 e.preventDefault()
63
64 // avoid scroll for urls with anchor refs
65 let { scroll } = this.props
66 if (scroll == null) {
67 scroll = as.indexOf('#') < 0
68 }
69
70 // replace state instead of push if prop is present
71 const { replace } = this.props
72 const changeMethod = replace ? 'replace' : 'push'
73
74 // straight up redirect
75 Router[changeMethod](href, as, { shallow })
76 .then((success) => {
77 if (!success) return
78 if (scroll) {
79 window.scrollTo(0, 0)
80 document.body.focus()
81 }
82 })
83 .catch((err) => {
84 if (this.props.onError) this.props.onError(err)
85 })
86}
210openExternalLink(href) {
211 const a = document.createElement('a')
212 a.href = link
213 a.target='_blank'
214 a.click()
215}
90openUrl(urlToOpen) {
91 Linking.openURL(urlToOpen);
92}
168function redirect(url){
169 console.log('redirect')
170 window.location.href = url
171 }

Related snippets