Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot initialize router when used via CommonJS #332

Open
timwis opened this issue May 24, 2016 · 6 comments
Open

Cannot initialize router when used via CommonJS #332

timwis opened this issue May 24, 2016 · 6 comments

Comments

@timwis
Copy link

timwis commented May 24, 2016

Hey folks, I've been trying to debug this for the past hour but have decided it may not be just me.

const Router = require('director').Router

const router = new Router({
  '/': () => console.log('root'),
  '/foo': () => console.log('foo')
})
router.init()

Yields the error router.init is not a function on index.js:19.

The documentation isn't quite clear on whether init() is necessary, so I tried without that line and the error goes away but the router doesn't appear to have any effect (nothing is logged). I also tried without new, but it tells me this.configure is not a function.

I'm trying to use this within an electron app, which has native support for require(), though I can't imagine it's any different than using a bundler like browserify/webpack. Any advice on how to use this lib?

@PaulMaly
Copy link

PaulMaly commented Jun 4, 2016

Join the question.

@teawithfruit
Copy link

I do it this way, and it works.

import {Router} from 'director'

class Routing {
  constructor() {
    let router = Router({
      '/': this.index,
      '/route/': this.route
    });
    router.init();
  }

  index() {
    console.log('index')
  }

  route() {
    console.log('route')
  }
}

@rnons
Copy link

rnons commented Nov 9, 2016

Try import { Router } from 'director/build/director';

Look into package.json, you can see "main": "./lib/director", there is actually no init method in lib/director.

@bibiuc
Copy link

bibiuc commented Dec 6, 2016

+1.查看代码后才知道是这么玩

@timwis
Copy link
Author

timwis commented Dec 6, 2016

I just ended up using sheet-router on the client and server-router on the server. Quite simple.

michaelgmcd added a commit to michaelgmcd/bs-director that referenced this issue May 13, 2017
This commit replaces the "director" module with "director/build/director". Per this issue: flatiron/director#332
michaelgmcd added a commit to michaelgmcd/bs-director that referenced this issue May 13, 2017
This commit replaces the "director" module with "director/build/director". Per this issue: flatiron/director#332
chenglou pushed a commit to reasonml-community/bs-director that referenced this issue Jun 1, 2017
This commit replaces the "director" module with "director/build/director". Per this issue: flatiron/director#332
@cweekly
Copy link

cweekly commented Jan 23, 2019

import { Router } from 'director';
// -> "TypeError: (intermediate value).configure(...).init is not a function"

import { Router } from 'director/build/director';
// No problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants