flutter web 访问url去除#号以及去除后直接访问指定地址404处理
在flutter web目录下新建访问的地址文件夹,创建index.html文件,index.html内写入重定向语句。使用url_strategy包。2.处理直接访问404。
·
1.去除url中#:
使用url_strategy包
import 'package:url_strategy/url_strategy.dart';
void main() {
// Here we set the URL strategy for our web app.
// It is safe to call this function when running on mobile or desktop as well.
setPathUrlStrategy();
runApp(MyApp());
}
2.处理直接访问404
在flutter web目录下新建访问的地址文件夹,创建index.html文件,index.html内写入重定向语句
如:
index.html:
<head>
<script type="text/javascript">
var currentUrl = window.location.href;
console.log(currentUrl);
const arr=currentUrl.split('/collect');
window.location.assign(arr[0]+arr[1]);
</script>
</head>
更多推荐
已为社区贡献5条内容
所有评论(0)