From 4a10734dcf858c6363af719a5886a24ec1115b33 Mon Sep 17 00:00:00 2001 From: senique Date: Sat, 22 Jun 2019 20:09:03 +0800 Subject: [PATCH] fix: paths of same prefix problem. (#4560) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Paths of same prefix will return the last match. It will occurs: Routes: { path: '/', authority: ['admin', 'user'] routes: [ { path: '/prefix2', authority: ['user'] }, { path: '/prefix', authority: ['admin'] }, ] } Problem: When user visit the '/prefix2', it will match the '/prefix', then Exception403 occurs. --- src/pages/Authorized.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/Authorized.tsx b/src/pages/Authorized.tsx index 9951b11e..8de52d42 100644 --- a/src/pages/Authorized.tsx +++ b/src/pages/Authorized.tsx @@ -14,7 +14,10 @@ const getRouteAuthority = (path: string, routeData: Route[]) => { routeData.forEach(route => { // match prefix if (pathToRegexp(`${route.path}(.*)`).test(path)) { - authorities = route.authority || authorities; + // exact match + if (route.path === path) { + authorities = route.authority || authorities; + } // get children authority recursively if (route.routes) { authorities = getRouteAuthority(path, route.routes) || authorities; -- GitLab