JavaScript How to reload page/router in handleSubmit method after submit? reload page router angular,reload router page,reload page react

I have a component with a login form.

What I need to do is to get it to reload the page / route after the user clicks the submit button.

The reason for this is that after the submit button is clicked some changes are needed on the nav component which is not this one.

You can see that I use sessionStorage.setItem('something', 'somevalue'); which then the nav component reads and makes some changes.

At the moment to get to see the changes I need to reload the browser.

Here is the code:

class Login extends Component {
  constructor(props) {
    super(props);
    this.state = {
      username: '',
      password: '',
    };

    this.onUsernameChange = this.onUsernameChange.bind(this);
    this.onPasswordChange = this.onPasswordChange.bind(this);
  }

  onUsernameChange(event) {
    this.setState({ username: event.target.value });
  }

  onPasswordChange(event) {
    this.setState({ password: event.target.value });
  }

  handleSubmit() { 
    event.preventDefault();
    sessionStorage.setItem('something', 'somevalue');
    // reload the page here or re-router to current page/router

  }

  render() {

    return (
        <div>
          <form className="form-signin" onSubmit={this.handleSubmit}>
            <input type="text" value={this.username} onChange={this.onUsernameChange} />
            <input type="password" value={this.password} onChange={this.onPasswordChange} />
            <input type="submit" value="Submit" />
          </form>
        </div>
    );
  }
}

export default Login;

How can I fix this problem?

Answer:1

A good idea would be to use onEnter callbacks in your routes or subscribe to changes on sessionStore (is that a redux store?) to check for updates, and allow that information to propagate down through the app.

To answer your question about navigation, however, you can use either:

location.reload() - location is a standard JavaScript (browser) object

or inject React Router's router using the provided withRouter component enhancer.

import { withRouter } from 'react-router'

...

export default withRouter(Login);

router will be available in props - you can use it like

const { router } = this.props
router.push('/some/route')

this will trigger a view change without reloading the window (which is why I was suggesting making sure that you can update your component's knowledge about the session without reloading the page)

edit - by the way event is undefined in handleSubmit

Answer:2

I have a javascript function which returns an boolean in some cases or an Observable in some other cases. Can I somehow always return an Observable by creating Observable out of a boolean?

I have a javascript function which returns an boolean in some cases or an Observable in some other cases. Can I somehow always return an Observable by creating Observable out of a boolean?

  1. convert primitive boolean to string
  2. convert primitive boolean to string java
  3. convert boolean to primitive
  4. convert boolean object to primitive
  5. convert boolean object to primitive java
  6. convert boolean wrapper to primitive in java
  7. java convert boolean to primitive

I'm using ajax file uploader on my pages. https://github.com/blueimp/jQuery-File-Upload I'm using one control for image uploading and another for file uploading and both are on the same page. I've ...

I'm using ajax file uploader on my pages. https://github.com/blueimp/jQuery-File-Upload I'm using one control for image uploading and another for file uploading and both are on the same page. I've ...

  1. disable drag drop javascript
  2. disable drag drop css
  3. disable drag drop windows 10
  4. disable drag drop
  5. disable drag drop angular
  6. disable drag drop sharepoint
  7. disable drag drop textarea
  8. disable drag drop folder windows 7
  9. disable drag drop excel
  10. disable drag drop windows explorer
  11. disable drag drop wpf
  12. disable drag drop in summernote
  13. disable drag drop folder
  14. disable drag drop file
  15. disable drag&drop jquery
  16. prevent drag drop
  17. remove drag drop jquery
  18. disable drag and drop html
  19. disable drag and drop in textbox javascript
  20. disable drag and drop windows 7

Trying to paint each cube face with a different color, I found a thread that presents a way to achieve this: var geometry = new THREE.BoxGeometry(5, 5, 5); for (var i = 0; i < geometry.faces....

Trying to paint each cube face with a different color, I found a thread that presents a way to achieve this: var geometry = new THREE.BoxGeometry(5, 5, 5); for (var i = 0; i < geometry.faces....

  1. cube painted faces

I try to use ContextMenu to run DeleteMaker function, but ContextMenu just get marker current Latlng, not like other leaflet events like "click", "dblclick" ... what can get marker options info. ...

I try to use ContextMenu to run DeleteMaker function, but ContextMenu just get marker current Latlng, not like other leaflet events like "click", "dblclick" ... what can get marker options info. ...

  1. leaflet marker options r
  2. leaflet marker options example
  3. leaflet marker options
  4. leaflet marker cluster options
  5. leaflet update marker options
  6. leaflet change marker options
  7. leaflet circle marker options
  8. leaflet marker set options
  9. leaflet get marker options
  10. leaflet default marker options
  11. leaflet marker icon options
  12. leaflet marker custom options
  13. leaflet marker popup options
  14. leaflet draw marker options
  15. leaflet js marker options
  16. leaflet marker bindpopup with options
  17. r leaflet marker cluster options