Commit 4a10734d authored by senique's avatar senique Committed by 陈帅

fix: paths of same prefix problem. (#4560)

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.
parent e4186a43
...@@ -14,7 +14,10 @@ const getRouteAuthority = (path: string, routeData: Route[]) => { ...@@ -14,7 +14,10 @@ const getRouteAuthority = (path: string, routeData: Route[]) => {
routeData.forEach(route => { routeData.forEach(route => {
// match prefix // match prefix
if (pathToRegexp(`${route.path}(.*)`).test(path)) { if (pathToRegexp(`${route.path}(.*)`).test(path)) {
authorities = route.authority || authorities; // exact match
if (route.path === path) {
authorities = route.authority || authorities;
}
// get children authority recursively // get children authority recursively
if (route.routes) { if (route.routes) {
authorities = getRouteAuthority(path, route.routes) || authorities; authorities = getRouteAuthority(path, route.routes) || authorities;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment