2

When a user submits a form on my site, I want to redirect them to the next state in my application using Angular UI Router so the user can't hit their back button to go back or refresh button to resubmit the form. But I don't want to do a page refresh.

I've tried these but didn't work:

$location.path('/myPath').replace(); $state.transitionTo('about', {}, { location: 'replace' }); 

How can I redirect users to another state in AngularJS with the Angular UI Router?

4
  • 2
    reset the form model after submission, it will prevent duplicate entry Commented Mar 5, 2015 at 5:42
  • Angular is a SPA framework, and as such, it's not really compatible with the the PRG pattern. Commented Mar 5, 2015 at 5:56
  • Angular UI Router has the default functionality of updating the browser history stack (window.history object). The back and forward buttons rely on the browser's history. So i guess you have to use other simple XMLHttpRequest APIs , if you want users not to access the previous state with back button Commented Mar 5, 2015 at 7:24
  • Agree with @Saqueib, keep it simple and just clear the form upon successful form submittal so they can't resubmit the form. Simply show a prompt or message on the page letting them know the form was submitted successfully and leave it at that. Commented May 13, 2015 at 15:12

1 Answer 1

2

Just go to the new state and use the location:replace option

$state.go('about', {}, { location: 'replace' }); 

See https://github.com/angular-ui/ui-router/wiki/Quick-Reference#options

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.