fix pathToRegexp not work

This commit is contained in:
Baorong Li
2020-03-20 11:59:04 +08:00
parent 82b3a4b384
commit 8d050d4040
10 changed files with 14 additions and 14 deletions
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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
View File
@@ -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',
})
+2 -2
View File
@@ -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' })
+1 -1
View File
@@ -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 {
+1 -1
View File
@@ -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: {
+1 -1
View File
@@ -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
View File
@@ -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) {
+4 -4
View File
@@ -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')
)
})