visionmedia / page.js

Micro client-side router inspired by the Express router
http://visionmedia.github.com/page.js
7.67k stars 687 forks source link

window is undefined #537

Open JosephScript opened 5 years ago

JosephScript commented 5 years ago

I have the following code:

  console.log(window)
  page(encodeURI(path), state, dispatch, push)

As you can see, the console log shows window is an object, yet the page transition fails.

image

It happens in this line of code: this.title = (hasDocument && window.document.title);

Any idea why the window might be undefined? (This is in the browser, not SSR.)

Thanks!

kjantzer commented 5 years ago

Reading through the source code, I found that the window property can be set using the configure method. Try this:

page.configure({window:window})

(not sure why this would be required to set manually)

btknorr commented 4 years ago

I ran into this as well...why in the world do we have to set page.configure({window:window}) to make this library work?

matthewp commented 4 years ago

@btknorr PRs welcome

blubbll commented 4 years ago

had the same problem, got the error Cannot read property 'document' of undefined thanks, @kjantzer