Browse Source

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.
pull/4592/head
senique 7 years ago
committed by 陈帅
parent
commit
4a10734dcf
  1. 5
      src/pages/Authorized.tsx

5
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;

Loading…
Cancel
Save