Skip to content

Instantly share code, notes, and snippets.

@mcky
Last active August 29, 2015 14:08
Show Gist options
  • Save mcky/6e956c71c645d4657d55 to your computer and use it in GitHub Desktop.
Save mcky/6e956c71c645d4657d55 to your computer and use it in GitHub Desktop.

Can't seem to loop through <Location> components using .map as I get the following error as it's being passed as a string:

Error: Invariant Violation: Route handler should be a component or a function but got: MainPage

Array in question and the component:

[{
	'path': '/',
	'handler': 'MainPage'
},{
	'path': '/users/:userName',
	'handler': 'UserPage'
}]
var App = React.createClass({
	render: function() {
		var createRoute = function(item) {
			return <Location path={item.path} handler={item.handler} />
		}
		return (
			<Locations path={this.props.path}>
				{this.props.paths.map(createRoute)}
				<NotFound handler={NotFoundPage} />
			</Locations>
		)
	}
})
@mcky
Copy link
Author

mcky commented Oct 30, 2014

It works! Thanks

Just had to switch item.handler to test[item.handler] - just need to convert test to module.exports now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment