提交 d4d5ad4b 编写于 作者: L Luis Fernando Alvarez D 提交者: Tim Neutkens

Remove propertyFields from the client router (#8219)

* Remove forEach over the components prop

* Remove propertyFields
上级 beed65be
...@@ -29,8 +29,7 @@ const singletonRouter: SingletonRouterBase = { ...@@ -29,8 +29,7 @@ const singletonRouter: SingletonRouterBase = {
} }
// Create public properties and methods of the router in the singletonRouter // Create public properties and methods of the router in the singletonRouter
const urlPropertyFields = ['pathname', 'route', 'query', 'asPath'] const urlPropertyFields = ['pathname', 'route', 'query', 'asPath', 'components']
const propertyFields = ['components']
const routerEvents = [ const routerEvents = [
'routeChangeStart', 'routeChangeStart',
'beforeHistoryChange', 'beforeHistoryChange',
...@@ -55,7 +54,7 @@ Object.defineProperty(singletonRouter, 'events', { ...@@ -55,7 +54,7 @@ Object.defineProperty(singletonRouter, 'events', {
}, },
}) })
propertyFields.concat(urlPropertyFields).forEach(field => { urlPropertyFields.forEach(field => {
// Here we need to use Object.defineProperty because, we need to return // Here we need to use Object.defineProperty because, we need to return
// the property assigned to the actual router // the property assigned to the actual router
// The value might get changed as we change routes and this is the // The value might get changed as we change routes and this is the
...@@ -149,18 +148,6 @@ export function makePublicRouterInstance(router: Router): NextRouter { ...@@ -149,18 +148,6 @@ export function makePublicRouterInstance(router: Router): NextRouter {
// Events is a static property on the router, the router doesn't have to be initialized to use it // Events is a static property on the router, the router doesn't have to be initialized to use it
instance.events = Router.events instance.events = Router.events
propertyFields.forEach(field => {
// Here we need to use Object.defineProperty because, we need to return
// the property assigned to the actual router
// The value might get changed as we change routes and this is the
// proper way to access it
Object.defineProperty(instance, field, {
get() {
return _router[field]
},
})
})
coreMethodFields.forEach(field => { coreMethodFields.forEach(field => {
instance[field] = (...args: any[]) => { instance[field] = (...args: any[]) => {
return _router[field](...args) return _router[field](...args)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册