如何重定向和重新加载正确的方式在Dart? [英] How to redirect and reload the right way in Dart?

查看:227
本文介绍了如何重定向和重新加载正确的方式在Dart?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Dart中执行重定向和重新载入的首选方式是什么?



我们只需要使用: window.location.href = window.location.href

解决方案

有几种不同的方式来处理URI更改和有自己的目的。


  1. 当您要将用户发送到另一个URI时:




    • window.location.assign('http://google.com')



      这会将用户发送给Google,保留浏览历史记录(返回按钮历史记录)。这类似于点击链接。


    • window.location.href ='http://google.com'



      与上面一样,只是另一种方法。 href 是一个setter,并导致分配发生。


    • window.location.replace('http://google.com'); / code>



      但是,上的<> $ replace() LocalLocation 对象不仅将用户发送给Google,而且不会将原始页面放在会话历史记录中,这意味着用户不会受到无休止的按钮噩梦。



      这本质上与HTTP重定向相同。跳过历史记录。



  2. 当您想要重新载入/ b
    $ b


    • window.location.assign(window.location.href)



      将当前页面重新加载到完全相同的URI。这样包含 POST 数据。一些资源(如图像等)可能从缓存重新加载,因此可能不是完全重新加载。



      这基本上与按< kbd> F5 并跳过 POST 数据的发送。


    • window.location.href = window.location.href



      同上一样。


    • window.location.reload()



      页面也会导致发送 POST 数据。 window.location.reload() 还支持指定是否跳过高速缓存的参数。但是,目前的Dart实现不支持该参数,并且默认从缓存中获取资源。



      这个缓存参数可能会添加到Dart,还没有。当它到达时,你最可能只是传递 true 作为第一个参数,然后它将像 Ctrl + Shift + R





摘要




  • 我想模拟< a> 标记的点击。 / ul>

    使用 window.location.assign(url)




    • 我想重定向到一个新的网站,如HTTP重定向,并跳过后退按钮历史记录。



    使用 window.location.replace(url)




    • 我想使用 POST 数据执行 F5 / ul>

      使用 window.location.reload()




      • 我想要执行 F5 而不使用 POST b $ b


      使用 window.location.assign(window.location.href)




      • 我要执行 Ctrl + Shift + F5



      不可用,也许在将来。它可能是 window.location.reload(true)


      What are the preferred ways to do a redirection and a reload in Dart?

      Do we just use: window.location.href = window.location.href?

      解决方案

      There are a few different ways to handle URI changes and each have their own purpose.

      1. 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. href is 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 on LocalLocation object 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.

      2. 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 POST data. 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 POST data.

        • window.location.href = window.location.href

          Again, the same as previous.

        • window.location.reload()

          This way of reloading the page causes also the POST data to be sent. The "JavaScript version" of window.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 true as the first parameter and then it would be like Ctrl + Shift + R.

      Summary

      • I want to simulate a click on <a> tag.

      Use window.location.assign(url).

      • I want to redirect to a new website like the HTTP redirection and skip the back-button history.

      Use window.location.replace(url).

      • I want to do an F5 with POST data.

      Use window.location.reload().

      • I want to do an F5 without POST data.

      Use window.location.assign(window.location.href).

      • I want to do an Ctrl + Shift + F5.

      Not available, maybe in the future. It would probably be window.location.reload(true).

      这篇关于如何重定向和重新加载正确的方式在Dart?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆