Router: Invariant Violation: You can only start the router once
Closed this issue · 4 comments
Having a little trouble getting the router to work Caused by this line as soon as we comment this out we are able to get things moving forward a little. We placed a debugger on this line a check that started is set to false, but once we continue execution it blows up. After commenting it out there are other errors we get with setReactElement
not available on this inside the routes. We are working on pr for these errors but you may already have something in the pipeline.
Output from the debugger in the route handler: (notes in route.js)
main.coffee
Layout = require('src/layout/components/layout_foo')
routes = require('./routes')
React.render(<Layout />, document.getElementById('lendesk-app'));
Router
.defaultRoute('/')
.register(routes)
.start(); # make sure to call start
layout.js (our controller view)
import React from 'react';
import { RouterStore } from 'fluxthis';
export default React.createClass({
displayName: 'Layout',
mixins: [RouterStore.mixin], // Should use the immutable pure render mixin here :)
getStateFromStores() {
return {
reactElement: RouterStore.getReactElement(),
reactElementProps: RouterStore.getReactElementProps(),
queryParams: RouterStore.getQueryParams(),
pathParams: RouterStore.getPathParams(),
path: RouterStore.getPath()
};
},
render() {
const ReactComponent = this.state.reactElement;
if (!ReactComponent) {
return null;
}
return (
<div>
<ReactComponent {...this.state.reactElementProps} />
</div>
);
}
});
routes.js
let ReleaseNotes = require('src/release_notes/components/release_notes');
require("babel/polyfill")
export default (router) => {
router.route('/', 'root', function *defaultHander(next) {
this.redirectTo('/release_notes');
});
router.route('/release_notes', 'release_notes', function *(next){
//debugger When running this debugger this does not have a setReactElement method
this.setReactElement(ReleaseNotes);
yield *next // default id as prop
});
};
Thanks,
Aaron and Matt
Good catch. Sorry about the delay getting back. I'm going to attempt to fix it now / tonight.
Just fyi, this feature is experimental as noted in the docs. We plan to make it a full fledged feature once we are able to integrate it into addthis.com & test it fully.
v2.2.2 has been published.
Thank you very much for fixing this so quickly.