My goal is to define a nested url like so:
/dashboard/modules/12242433
I was using this example to model my code: React Router Examples: dynamic-segments
Here is my render method that defines my routes
render((
<Router history={browserHistory}>
<Route path="/" component={App}>
<Route path="dashboard" component={Dashboard}>
<Route path="modules" component={Modules}>
<Route path=":module_id" component={Module} />
</Route>
</Route>
</Route>
</Router>
), document.getElementById('app'));
I am able to go to /dashboard
, but as soon as I try to go to /dashboard/modules
or /dashboard/modules/123232
, I get an error message which doesn't seem to be very helpful:
bundle.js:2 Uncaught SyntaxError: Unexpected token <
Here are my components, my understanding was that this should work as long as I rendered the comps children.
Dashboard
import React from 'react'
export default React.createClass({
render() {
return (
<div>
<p> Hello, Dashboard! </p>
{ this.props.children }
</div>
)
}
})
Modules
import React from 'react'
export default React.createClass({
render() {
return (
<div>
<p> Hello, Modules! </p>
{ this.props.children }
</div>
)
}
})
Module
import React from 'react'
export default React.createClass({
render() {
return (
<div>
<p> Hello, Single Module! </p>
</div>
)
}
})
Update
It turns out my code was correct(ish) but now I am even more confused. This navigation does work as long as you arrive to a URL via a click:
<NavLink to="/dashboard/modules/SomeModName">View Mod</NavLink>
I have been testing it simply by putting /dashboard/modules/SomeModName
in the URL, and this is what would always break.
Is there a way you can have this URL work both ways?
I have found a second bug and I think they are related..
When I click the link which takes me to /dashboard/modules
it loads correctly, however when I hit refresh, it gives me the original error.
What core piece of React Router have I overlooked?
Second Update When I pull this code down locally from the example I am able to reintroduce the bug (the page breaks upon refresh when in detail view). The refresh however does not break when you clone the whole repo and run it as is. What is it that effects this behavior?
React Router Master-Detail Example
webpack.config.js
var path = require('path');
var webpack = require('webpack');
module.exports = {
devtool: 'eval',
entry: [
'webpack-hot-middleware/client',
'./client/index'
],
output: {
path: path.join(__dirname, 'static'),
filename: 'bundle.js',
publicPath: '/static/'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
module: {
loaders: [
{
test: /\.json$/,
loader: 'json'
},
{
test: /\.js$/,
loader: 'babel-loader',
include: path.join(__dirname, 'client'),
query: {
plugins: ['transform-runtime'],
presets: ['es2015', 'stage-0', 'react', 'react-hmre']
}
},
{
test: /\.scss$/,
loaders: ['style', 'css', 'sass']
}
]
}
};