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

Uncaught TypeError: Cannot set property 'href' of null #515

Closed estebanpdl closed 1 year ago

estebanpdl commented 5 years ago

I have been using page.js for nodejs applications in different projects, however, my newest one is exploring a massive download data from a postgresql database, which affects how elements are been rendered.

What is the best approach to make anchor tags works?, for example:

const page = require('page')
const d3 = require('d3')
page('/view', (ctx, next) => {
  let qs = ctx.querystring
  let a = d3.select('#get-back')
  a.attr('href', `/?${qs}`)

  next()
}

After I click the anchor tag in view, I get Uncaught TypeError: Cannot set property 'href' of null. If element is not available, how can I use page.js to make the link works and return to home view where data was downloaded?

I tried a setTimeout function, but I do not know if this is the best approach.