kitze/mobx-router

a bit lose with the samples, getting error store.router is undefined

Closed this issue · 5 comments

Hi!!..I'm trying to use mobx-router with this boilerplate unfortunately I'm a bit lose because seems than this sample use an older version of mobx-router and I'm a bit noob using mobx

The file structure between the sample and the boilerplate is similar, my App.js ooks like this

// @flow

import React, {PropTypes} from 'react'
import { observer } from 'mobx-react'

import MyComponent from './MyComponent'
import { Provider } from 'mobx-react'
import views from './../config/views'
import Store from './../stores/Store'

import {MobxRouter,startRouter} from 'mobx-router'

const store = new Store()
console.log('store es ' + store.router); //====> undefined

startRouter(views,store)

@observer
class App extends React.Component {
  render() {
    return (
      <Provider store={store}>
        <MobxRouter></MobxRouter> 
      </Provider>
      
    )
  }
}


export default App

and the Store looks like this, I add the router parameter because I look this in the readme

import { observable, computed } from 'mobx'
import {routerStore} from 'mobx-router'

class Store {
  //Autorun is a function from MobX that runs everytime that something inside is
  //updated. In the example below, everytime 'numClicks' is updated, autorun will run
  //the console.warn
  //
  // import {autorun} from 'mobx'
  // constructor() {
  //   autorun(() => console.warn('MobX autorun - Whenever numClicks has it value updated, console.log runs: ', this.numClicks))
  // }

  name = 'Reaxor';
 //this router is generating me troubles!!!!
  router = routerStore; //must be an observable??

  description = 'boilerplate for better state management, styling, testing and cleaner code';
  @observable numClicks = 0;

  @computed get oddOrEven() {
    return this.numClicks % 2 === 0 ? 'event' : 'odd'
  }



  clickButton = () => {
    this.numClicks++
  }
}

export default Store

the import {routerStore} from 'mobx-router' is generating troubles, mobx-router includes this field?...I install mobx-router with the typical npm install mobx-router --save

thank you

Something seems to have changed in the API so that now the RouterStore class is exposed instead of an instance. If you import RouterStore and instantiate it with new it will work. But this means the documentation needs to be updated to reflect that.

I am getting this error when I navigate using goTo, the store passed to beforeEnter is undefined.

@marlonsupetran that's a completely different problem. See #60

thdk commented

closed in #92