Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
fix(router): handle undefined routes
Browse files Browse the repository at this point in the history
  • Loading branch information
hmdhk committed May 18, 2017
1 parent faa2b30 commit 49062fc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function combineRoutes (routes) {
}

function makeSignatureFromRoutes (routes, location) {
if (routes.length < 1) {
if (!routes || routes.length < 1) {
return 'unknown'
}
var fullRoute
Expand Down
30 changes: 28 additions & 2 deletions test/e2e/router/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,31 @@ function loadComponent(prom) {
}
}

module.exports = (

var plainRoutes = {
path:'/router',
component:App,
indexRoute:{
component:Index
},
childRoutes:[
{
path:'/about1',
getComponent:loadComponent(() => System.import('./about_component') )
},
{
path:'/about2',
getComponent:(nextState, cb) => {
require.ensure([], function (require) {
cb(null, [
require('./about_component').default,
])
})}
}
]
}

var routes = (
<Route path="/router" component={App}>
<IndexRoute component={Index}/>
<Route path="/about1" getComponent={loadComponent(() => System.import('./about_component') )} />
Expand All @@ -21,4 +45,6 @@ module.exports = (
])
})}} />
</Route>
)
)

module.exports = routes
3 changes: 2 additions & 1 deletion test/react/router.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ describe('react-router: makeSignatureFromRoutes', function () {
expect(makeSignatureFromRoutes(routes, pushLocation)).toBe('/something')
})

it('should handle zero routes', function () {
it('should handle zero or undefined routes', function () {
expect(makeSignatureFromRoutes([], pushLocation)).toBe('unknown')
expect(makeSignatureFromRoutes(undefined, pushLocation)).toBe('unknown')
})

it('should handle REPLACE routes', function () {
Expand Down

3 comments on commit 49062fc

@aksel
Copy link

@aksel aksel commented on 49062fc Jun 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any word on when this will be part of a release?

@hmdhk
Copy link
Contributor Author

@hmdhk hmdhk commented on 49062fc Jun 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reaching out @aksel ,

We're finishing up with a couple of more issues before we release this.
But it should be released within the next 2 weeks.

@hmdhk
Copy link
Contributor Author

@hmdhk hmdhk commented on 49062fc Jun 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aksel ,
I have released [email protected] which includes this fix.
Let me know how it goes.

Cheers

Please sign in to comment.