h5实现页面跳转
使用 <a> 标签实现跳转
通过 HTML 的 <a> 标签直接跳转到目标页面,适用于静态链接:
<a href="target.html">跳转到目标页</a>
href属性指定目标页面的路径(相对路径或绝对路径)。- 默认在当前窗口打开,添加
target="_blank"可在新标签页打开。
使用 JavaScript 实现跳转
通过 window.location 或 window.open 动态控制跳转,适合需要逻辑判断的场景:

// 当前窗口跳转
window.location.href = "target.html";
// 新窗口打开
window.open("target.html", "_blank");
window.location.replace()会替换当前历史记录,用户无法返回原页面。
使用路由跳转(单页应用 SPA)
适用于 Vue、React 等框架的单页应用,通过路由库实现无刷新跳转:

// Vue Router 示例
this.$router.push("/target-page");
// React Router 示例
import { useNavigate } from "react-router-dom";
const navigate = useNavigate();
navigate("/target-page");
通过表单提交跳转
表单的 action 属性可指定提交后跳转的页面:
<form action="target.html" method="GET">
<input type="submit" value="提交并跳转">
</form>
使用 meta 标签自动跳转
通过 <meta> 标签设置页面自动刷新或跳转:
<meta http-equiv="refresh" content="5;url=target.html">
content="5;url=..."表示 5 秒后跳转。
注意事项
- 路径需确保正确:相对路径基于当前文件位置,绝对路径以
/开头。 - 单页应用需提前配置路由规则,避免 404 错误。
- 动态跳转前可添加条件判断(如登录状态检查)。






