-1

In react how do you redirect or open something in new tab? I have a button and on click I want to open it in new tab. For now it opens in current tab. here is the button code

<Button
                                  variant="contained"
                                  fullWidth={true}
                                  color="primary"
                                  disabled={loder === data._id ? true : false}
                                  onClick={() => viewRecording(data)}
                                >

Here is that function

const viewRecording = (sessionData) => {
    setLoder(sessionData._id);
    const val = {
      meetingId: sessionData.meetingNo,
    };
    const onSuccess = (data) => {
      setLoder(null);
      console.log(data.recording_files);
      window.location.replace(data.recording_files[0].play_url);
    };
    const onError = () => {
      setLoder(null);
      openSnackbar("Recording not found for this session !!");
    };
    dispatch(ZoomMeetingRecording(val, onSuccess, onError));
  };
Vaibhaw kr
  • 151
  • 1
  • 10
  • Does this answer your question? [JavaScript: location.href to open in new window/tab?](https://stackoverflow.com/questions/5141910/javascript-location-href-to-open-in-new-window-tab) – Quentin Feb 17 '21 at 10:01
  • @Quentin how can implement it in my current case? – Vaibhaw kr Feb 17 '21 at 10:15

1 Answers1

2

Just use

window.open(data.recording_files[0].play_url, '_blank'); 

Instead of

window.location.replace(data.recording_files[0].play_url);
Osadhi Virochana
  • 1,294
  • 2
  • 11
  • 21