mirror of
https://github.com/zuiidea/antd-admin
synced 2026-11-06 04:04:58 +00:00
fix pathToRegexp not work
This commit is contained in:
@@ -40,7 +40,7 @@ class Bread extends PureComponent {
|
||||
|
||||
// Find a route that matches the pathname.
|
||||
const currentRoute = routeList.find(
|
||||
_ => _.route && pathToRegexp(_.route, location.pathname)
|
||||
_ => _.route && pathToRegexp(_.route).exec(location.pathname)
|
||||
)
|
||||
|
||||
// Find the breadcrumb navigation of the current route match and all its ancestors.
|
||||
|
||||
@@ -80,7 +80,7 @@ class SiderMenu extends PureComponent {
|
||||
|
||||
// Find a menu that matches the pathname.
|
||||
const currentMenu = menus.find(
|
||||
_ => _.route && pathToRegexp(_.route, location.pathname)
|
||||
_ => _.route && pathToRegexp(_.route).exec(location.pathname)
|
||||
)
|
||||
|
||||
// Find the key that should be selected according to the current menu.
|
||||
|
||||
@@ -70,7 +70,7 @@ class PrimaryLayout extends PureComponent {
|
||||
|
||||
// Find a route that matches the pathname.
|
||||
const currentRoute = newRouteList.find(
|
||||
_ => _.route && pathToRegexp(_.route, location.pathname)
|
||||
_ => _.route && pathToRegexp(_.route).exec(location.pathname)
|
||||
)
|
||||
|
||||
// Query whether you have permission to enter this page
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ import config from 'config'
|
||||
const { queryRouteList, logoutUser, queryUserInfo } = api
|
||||
|
||||
const goDashboard = () => {
|
||||
if (pathToRegexp(['/', '/login'], window.location.pathname)) {
|
||||
if (pathToRegexp(['/', '/login']).exec(window.location.pathname)) {
|
||||
history.push({
|
||||
pathname: '/dashboard',
|
||||
})
|
||||
|
||||
@@ -35,8 +35,8 @@ export default modelExtend(model, {
|
||||
setup({ dispatch, history }) {
|
||||
history.listen(({ pathname }) => {
|
||||
if (
|
||||
pathToRegexp('/dashboard', pathname) ||
|
||||
pathToRegexp('/', pathname)
|
||||
pathToRegexp('/dashboard').exec(pathname) ||
|
||||
pathToRegexp('/').exec(pathname)
|
||||
) {
|
||||
dispatch({ type: 'query' })
|
||||
dispatch({ type: 'queryWeather' })
|
||||
|
||||
@@ -16,7 +16,7 @@ export default {
|
||||
if (data.success) {
|
||||
const { from } = locationQuery
|
||||
yield put({ type: 'app/query' })
|
||||
if (!pathToRegexp('/login', from)) {
|
||||
if (!pathToRegexp('/login').exec(from)) {
|
||||
if (['', '/'].includes(from)) history.push('/dashboard')
|
||||
else history.push(from)
|
||||
} else {
|
||||
|
||||
@@ -11,7 +11,7 @@ export default modelExtend(pageModel, {
|
||||
subscriptions: {
|
||||
setup({ dispatch, history }) {
|
||||
history.listen(location => {
|
||||
if (pathToRegexp('/post', location.pathname)) {
|
||||
if (pathToRegexp('/post').exec(location.pathname)) {
|
||||
dispatch({
|
||||
type: 'query',
|
||||
payload: {
|
||||
|
||||
@@ -24,7 +24,7 @@ export default modelExtend(pageModel, {
|
||||
subscriptions: {
|
||||
setup({ dispatch, history }) {
|
||||
history.listen(location => {
|
||||
if (pathToRegexp('/user', location.pathname)) {
|
||||
if (pathToRegexp('/user').exec(location.pathname)) {
|
||||
const payload = location.query || { page: 1, pageSize: 10 }
|
||||
dispatch({
|
||||
type: 'query',
|
||||
|
||||
+1
-1
@@ -124,7 +124,7 @@ export function queryLayout(layouts, pathname) {
|
||||
const isMatch = regepx => {
|
||||
return regepx instanceof RegExp
|
||||
? regepx.test(pathname)
|
||||
: pathToRegexp(regepx, pathname)
|
||||
: pathToRegexp(regepx).exec(pathname)
|
||||
}
|
||||
|
||||
for (const item of layouts) {
|
||||
|
||||
@@ -2,17 +2,17 @@ const { pathToRegexp } = require("path-to-regexp")
|
||||
|
||||
describe('test pathToRegexp', () => {
|
||||
it('get right', () => {
|
||||
expect(pathToRegexp('/user', '/zh/user')).toEqual(
|
||||
expect(pathToRegexp('/user').exec('/zh/user')).toEqual(
|
||||
pathToRegexp('/user').exec('/user')
|
||||
)
|
||||
expect(pathToRegexp('/user', '/user')).toEqual(
|
||||
expect(pathToRegexp('/user').exec('/user')).toEqual(
|
||||
pathToRegexp('/user').exec('/user')
|
||||
)
|
||||
|
||||
expect(pathToRegexp('/user/:id', '/zh/user/1')).toEqual(
|
||||
expect(pathToRegexp('/user/:id').exec('/zh/user/1')).toEqual(
|
||||
pathToRegexp('/user/:id').exec('/user/1')
|
||||
)
|
||||
expect(pathToRegexp('/user/:id', '/user/1')).toEqual(
|
||||
expect(pathToRegexp('/user/:id').exec('/user/1')).toEqual(
|
||||
pathToRegexp('/user/:id').exec('/user/1')
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user