A powerful nuke could certainly alter an asteroid's trajectory. However, most of the energy would be wasted. It'd be better to use a nuclear propulsion reactor strapped to the side of the asteroid to direct it more accurately, but we don't have that technology today, whereas we do know how to make big bombs.
Also, the idea of changing an asteroid's trajectory just before it hits the Earth is crazy. You need much more warning, because even a big bomb isn't going to move the asteroid that much, so you need to use it long before it's projected to collide.
Also, the idea of changing an asteroid's trajectory just before it hits the Earth is crazy. You need much more warning, because even a big bomb isn't going to move the asteroid that much, so you need to use it long before it's projected to collide.