Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
153
rated 0 times [  157] [ 4]  / answers: 1 / hits: 22881  / 7 Years ago, tue, october 10, 2017, 12:00:00

Have the following app, and window.location is not configurable. I would ideally like to hit the submit button and go to an alternate domain.This is actually part of a larger app, in which I use an external Identity Provider for Signin. Snippet below is a fully working sample to illustrate the issue:



import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import Router from './routes';
import reducers from './reducers';
import { BrowserRouter, Route, Switch } from 'react-router-dom';

const store = createStore(reducers);

class Signin extends React.Component {
onSubmit() {
var result = Object.getOwnPropertyDescriptor(window, 'location');
window.location = 'http://www.bbc.co.uk';
}

render() {
return (
<div>
<form
className=form-horizontal col-xs-10 col-xs-offset-1
onSubmit={this.onSubmit.bind(this)}
>
<div className=form-group>
<span className=col-xs-3 />
<div className=col-sm-6>
<button type=submit className=btn btn-success btn-sm>
Submit
</button>
</div>
</div>
</form>
<script />
</div>
);
}
}

class App extends React.Component {
render() {
return (
<div>
<div className=container>{this.props.children}</div>
</div>
);
}
}

render(
<Provider store={store}>
<BrowserRouter>
<App>
<Switch>
<Route exact path=/ component={Signin} />
</Switch>
</App>
</BrowserRouter>
</Provider>,
document.getElementById('root')
);


You can see a working sample here



On my real app, am using the following dependencies and versions:



 prop-types: ^15.6.0
react: ^15.6.1
react-dom: ^15.6.1
react-redux: 4.3.0
react-router-dom: ^4.0.0
react-scripts: 1.0.13


You will notice I put in a line:



var result = Object.getOwnPropertyDescriptor(window, 'location');


This returns information about the location object and indicates configurable=false. The URL currently remains the same with a /? taggged on the end.



Can anyone offer any insights? Tried also window.location.href. It seems that perhaps react / react router is reconfiguring window.location to be un-configurable - is there any reason or workaround anyone can offer.


More From » reactjs

 Answers
7

OK, I wasn't suppressing the form submission.



 onSubmit(e) {
e.preventDefault();
window.location = https://www.bbc.co.uk;
}


Yes, that one again...


[#56259] Sunday, October 8, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kevonmoisesf

Total Points: 693
Total Questions: 101
Total Answers: 128

Location: Reunion
Member since Mon, Dec 28, 2020
3 Years ago
kevonmoisesf questions
Sat, Jan 23, 21, 00:00, 3 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
Wed, Jun 12, 19, 00:00, 5 Years ago
;