What are the preferred ways to do a redirection and a reload in Dart?
Do we just use: window.location.href = window.location.href?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are a few different ways to handle URI changes and each have their own purpose.
When you want to send the user to another URI:
window.location.assign('http://google.com')This one sends the user to Google, keeping the browsing history (the back button history). This is like clicking on a link.
window.location.href = 'http://google.com'The same as above, just another way to do it.
hrefis a setter, and causes the assignment to happen. I feel the previous version is cleaner.window.location.replace('http://google.com');However, the
replace()method onLocalLocationobject does not only send the user to Google, but also does not put the originating page in the session history, which means the user will not suffer from the never-ending back-button nightmare.This is essentially the same as an HTTP redirect. The history is skipped.
When you want to do a reload/refresh.
window.location.assign(window.location.href)Reloads the current page to the exact same URI. This does not contain
POSTdata. Some of the resources (like images, etc.) may me reloaded from the cache, so it might not be a full reload.This is essentially the same as pressing F5 and skipping the sending of
POSTdata.window.location.href = window.location.hrefAgain, the same as previous.
window.location.reload()This way of reloading the page causes also the
POSTdata to be sent. The “JavaScript version” ofwindow.location.reload()also supports a parameter that specifies whether to skip the cache or not. However, the current Dart implementation does not support that parameter, and defaults to fetch the resources from cache.This cache parameter may be added to Dart at some point, but it’s not there yet. When it arrives, you most likely just pass
trueas the first parameter and then it would be like Ctrl + Shift + R.Summary
<a>tag.Use
window.location.assign(url).Use
window.location.replace(url).POSTdata.Use
window.location.reload().POSTdata.Use
window.location.assign(window.location.href).Not available, maybe in the future. It would probably be
window.location.reload(true).