laravel - 如何在laravel中使用hashtag href创建路由
问题描述
我有指向具有 css 动画的不同页面的菜单链接。我的锚标签看起来像这样
我为此链接创建了一条路线,但它不起作用。
<a href="#about" class="icon-a fas fa-user-tie"></a>
"Route::get('#about',function () {
return view('about');
});
谁能帮我完成这个。
谢谢
解决方案
因为片段是由客户端处理的,所以在访问片段之前,客户端必须能够渲染 JavaScript。实现此目的的解决方案可能是:
在您的routes.php
文件中:
Route::get('/', function() {
return view('basic-javascript-router');
});
Route::get('/about', function() {
return view('about');
});
Route::get('/welcome', function() {
return view('welcome');
});
在您的项目/resources/views/
目录中添加一个简单的basic-javascript-router.php
文件:
<!DOCTYPE html>
<html>
<head>
<title>rerouting</title>
<script type="text/javascript">
function checkHash() {
if (window.location.hash && window.location.hash === '#about') {
window.location.href = '/about';
} else {
//direct users to the generic landing page
window.location.href = '/welcome';
}
}
window.onload = checkHash;
</script>
</head>
<body>
<p>rerouting...</p>
</body>
</html>
通常这是像 VueJS 这样的前端框架的工作,但这可能对你有用。
推荐阅读
- sql - 使用表示变量在 OBIEE 中转换直接 sql 查询的日期
- java - 登录用户和注册用户登录和注册功能
- c - 使用 C 代码连接到 Monetdb 时出现链接错误
- javascript - 基于不同数据属性的多级过滤DOM问题
- skype-for-business - Skype For Business Online UCWA 应用程序服务器在一段时间后停止工作
- python - 字符串集之间的差异不起作用
- java - h如何打印来自 Axis 1.4 存根的 XML 请求和响应
- active-directory - 活动目录 lastLogonTimestamp - 将整数转换为日期
- regex - 我想将双引号之间的每个字符串修剪为 16 个字符
- debugging - Roku 调试?