The only reason to blow up the asteroid while it's heading away would be if it were coming back. But if it's coming back, blowing it up "as it goes away from us" is really just blowing it up on the way in, just further ahead of time. It's still a bad idea for exactly the same reasons, you're just executing the breakup so the shrapnel with a total mass identical to the original asteroid shotgun-blasts into the planet on the next pass rather than on this pass. If you're trying to make it not head in our direction, it's actually a lot easier to do that if you don't break it up.
I imagine in your head you're picturing some kind of massive explosion that sends the mass of the asteroid flying in all directions, rather than just cracks the rock up into smaller asteroids in the same orbit. That would work, if we had something powerful enough to do that. A nuclear bomb wouldn't, however. Might as well suggest we use a stick of dynamite. At the time it was invented, in the popular imagination you could do anything with it, but really, it's just dynamite. Nowadays, since nuclear bombs are the most powerful explosive devices ever invented, again in the popular imagination you can do anything with them. But really, no. An asteroid large enough to really worry about is too large to be much affected by a nuclear bomb.