nprogress icon indicating copy to clipboard operation
nprogress copied to clipboard

Keep getting cannot find className of null

Open PanicIsReal opened this issue 8 years ago • 4 comments

I've done the setup according to the readme, but every time

Uncaught TypeError: Cannot read property 'className' of null
    at classList (bundle.js:34278)
    at addClass (bundle.js:34245)
    at Object.NProgress.render (bundle.js:34059)
    at Object.NProgress.set (bundle.js:33885)
    at Object.NProgress.inc (bundle.js:33985)
    at Object.NProgress.trickle (bundle.js:33990)
    at bundle.js:33942

Any suggestions?

PanicIsReal avatar Feb 12 '17 23:02 PanicIsReal

Seems to work after having removed the parent option from the new

PanicIsReal avatar Feb 12 '17 23:02 PanicIsReal

I'm also getting this. Digging around in the nprogress code since I don't see anything about it in this repo

EDIT: Aha! This happens when I try to call this.$nprogress.start() in the created hook of my component. If I wait until the mounted hook, everything works.

nelsonpecora avatar Feb 24 '17 17:02 nelsonpecora

I am also getting this issue, but I solved this buy review nprogress.js souce code:

var bar      = progress.querySelector(Settings.barSelector),
        perc     = fromStart ? '-100' : toBarPerc(NProgress.status || 0),
        parent   = document.querySelector(Settings.parent),
        spinner;
    
    css(bar, {
      transition: 'all 0 linear',
      transform: 'translate3d(' + perc + '%,0,0)'
    });

    if (!Settings.showSpinner) {
      spinner = progress.querySelector(Settings.spinnerSelector);
      spinner && removeElement(spinner);
    }

    if (parent != document.body) {
      addClass(parent, 'nprogress-custom-parent');
    }

the progress bar's default location is the top of window, but we can change this location by pass a node we prefer via the config option. Nprogress will select the node via

document.querySelector(Settings.parent)

So, the solution is, if we want to show the progress bar on the top of the window, just do not pass the parent option or just {parent:"body"}; if we want to set the progress bar in another place, pass the config option like {parent:".my-place"}, after that, you need to add a node with a class named "my-place" on your page, otherwise, it will show an error of null point exception. That's all, guys!

PearRichard avatar Jun 03 '17 09:06 PearRichard

close this issue

Cholowao avatar Jul 24 '18 07:07 Cholowao