[verb ます-stem] + がけに [verb ます-stem] + がけの + [noun]
がけに means "on the way" or "just as you leave": something else happens, or you do something else, while you are going somewhere. It attaches to the ます-stem of a handful of movement verbs, and the common ones are fixed words: かえりがけ帰りがけに, いきがけ行きがけに, でがけ出がけに, とおり通りがけに.
The verb goes in the ます-stem, not the dictionary form, and it has to be a verb of going somewhere.
出がけに is a moment, not a stretch of road: the instant you step out of the door. That is why it so often comes with something going wrong.
In everyday speech, かえり帰りに and いき行きに say the same as 帰りがけに and 行きがけに and are more common.
がけの describes a noun: the bus or train you took on the way.
がけ is not the かけ of たべかけ食べかけ and よみかけ読みかけ, which means "half-done".