如何重定向和重新加载正确的方式在Dart?

编程入门 行业动态 更新时间:2024-10-10 01:21:07
本文介绍了如何重定向和重新加载正确的方式在Dart?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

解决方案

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

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

    • window.location.assign('google')

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

    • window.location.href ='google'

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

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

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

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

  • 当您想要重新载入/ b $ b

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

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

      这基本上与按 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.

      • When you want to send the user to another URI:

        • window.location.assign('google')

          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 = 'google'

          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('google');

          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.

      • 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?

    本文发布于:2023-10-12 05:12:04,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:重定向   加载   正确   方式   Dart

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!