Gcode header/footer can be added to the beginning and end of your gcode file.
M03 or M04 will turn on the spindle/router
M05 will turn it off
The link you provided will work to switch the router power. You have to tie the relay to a specific pin on the shield.
There are several posts on the forum about how to do this:
first one of the list