(1)可以使用正则添加一条 Rewrite 规则,例如:要实现打开 URL:https://www.easck.com/search/原子弹时,将其拦截,改用本地已注册的URL:protocol://page/routerDetails?product=原子弹打开。
首先添加一条 Rewrite 规则:
[FFRouterRewrite addRewriteMatchRule:@"(?:https://www.easck.com/search/(.*)" targetRule:@"protocol://page/routerDetails?product=$1"];
之后在打开URL:https://www.easck.com/search/原子弹时,将会 Rewrite 到URL:protocol://page/routerDetails?product=原子弹。
[FFRouter routeURL:@https://www.easck.com/search/原子弹];
(2)可以通过以下方法同时增加多个规则:
+ (void)addRewriteRules:(NSArray<NSDictionary *> *)rules;
其中 rules 格式必须为以下格式:
@[@{@"matchRule":@"YourMatchRule1",@"targetRule":@"YourTargetRule1"},
@{@"matchRule":@"YourMatchRule2",@"targetRule":@"YourTargetRule2"},
@{@"matchRule":@"YourMatchRule3",@"targetRule":@"YourTargetRule3"},]
(3)Rewrite 规则中的保留字:
- 通过 $scheme、$host、$port、$path、$query、$fragment 获取标准 URL 中的相应部分。通过$url获取完整 URL
- 通过 $1、$2、$3...获取matchRule的正则中使用圆括号取出的参数
-
$:原变量的值、$$:原变量URL Encode后的值、$#:原变量URL Decode后的值
例如:https://www.easck.com/search/原子弹对于Rewrite 规则(?:https://www.easck.com/search/(.*)










