The curious thing about the descent of the H.L. is that its members did not really lose much; on the contrary, most Hansa cities went on accruing wealth.
They only obtained strong rivals like the Netherlands, Denmark and Sweden, and later England. So while they gained ever more trade volume, they lost market share and hence political power.
So the two main factors marginalizing the H.L. were the improved organization and thus rising power of states like Denmark, England, and Sweden; and the discovery of the Americas which increased the market volume of sea trade without a share for good ol' Hansa. So an obvious way of empowering Hansa would be let them take part in the trade with the new world. It is, however, doubtful how and why they would get the rights to do so from a genuine colonial power; I think it would be too much of a stretch to let the found colonies from scratch - the Hansa cities had much less rural manpower backup than the Dutch port cities. What about Portugal relying on Hanseatic naval support for not having the necessary ressources (e.g. due to a conflict with Castilia)?
As a comletely different scenario, let's think of the the Baltic coast in the age of reformation. Although most Hansa cities were early in converting to the new denominations, the secularization of the state of the Teutonic order was a serious blow to them. What about making Prussia a "colony" under joint administration of the Hansa cities (like a "common bailwick", as the Swiss would have called it)?
This is going to take some, um, efforts in dealing with Poland, whose attention, however, might be absorbed elsewhere ...
In general, a large base of ports around the Baltic is still a powerhouse in the 17th century.
And this leads us the the third main obstacle to Hansa continuation: In political terms, it was a very conservative association. While they put new naval technologies and commercial strategies into practice early (at least in earlier centuries), they certainly did not fantasize as much as we do in this thread by far. So in any case, you might need to change the political culture and the attitude towards the League and the world outside at least in some of the main member cities ...
(And btw, I think that the comparison to a military alliance like NATO is misleading, in spite of wars waged in the name of the H.L. The main purpose of it was always commercial in nature.)
While we now have compiled many suggestions as to how to maintain or expand the status of the Hansa from its peak of power onwards, it also seems interesting to me how it could still change tack and be revived in its later period (I guess that's the right metaphor for the Hansa?). I think that was part of the main question of this thread.
While the H.L. was not a decisive factor in the 16th century any more,
its actual deathblow came with the Thirty Years War. The defeat of Magdeburg as one of the major inland Hansa cities in contrast to the exploding population and wealth of Hamburg could not vindicate any linkage afterwards. Moreover, the Swedish (and later Brandenburgian) possession on both North Sea and Baltic coast blocked the chance for coordinated German trade (or even more, colonization).
What about the Hansa taking a stance in the Thirty Years War?
Against the Imperial Edict of Restitution, but also against Sweden and Denmark, neutral to the Netherlands - that would make a nice "Third Party" position for the Hanseatic League (think of an early Union of Leipzig). They would, of course, be in a lot of trouble without support from larger Protestant states (Saxony, Brandenburg, Lüneburg/Hannover).
This could as well endager the Hansa cities a lot and put an even more painful end to the H.L. Hanseatic success in this scenario would imply that Magdeburg is liberated in the late 1620s, which is improbable in oppostion to the Emperor (as well as Denmark, for that matter). It is also hard to imagine an Imperial-Hanseatic cooperation against Denmark (and the Netherlands!!?), as this would require to abandon a lot of restitution claims from counter-reformist side. But finding an ally against both the Danish intruder as well as the Dutch separatists may seem attractive to the Habsburgs ...
and I think, sufficiently attractive to negotiate terms about Protestant states. However, Bavaria would not like it and try to undermine that strategy (as would France, but France is not yet capable of exterior actions in the 1620s) ...
In my own TL, Germany is on a road where the empire will be more unified. It's not going to become a singular state overnight, and encompasses a wide area, but it's on the way. Is there any way that a centralizing empire might find a use for the Hanseatic League in terms of trade and the economy? Many of the Hansestadt where already Imperial Free Cities and would be represented in the Reichstag. For some reason, the idea of Hanse ships sailing west for the Emperor sound incredibly inciting

... and American and indeed, Asiatic trade might be just what they need to revive.
The H.L. was an alliance between free cities and not free cities in the Empire, so I think for an effective League, you will need a
weak central authority in the Empire. True, for the not-so-free cities, weaker central authority in the individual states of the Empire might also help.
The Hansa as a whole mandated with colonial, or at least intercontintal trade tasks by the Emperor seems like a good idea. However, I it is much easier for me to imagine this scenario if the Emperor acts only as Austrian Archduke (and European magnate).
A joint action of this sort by the whole of Germany is hardly possible.
Emperors like Charles V. and his successor would, however, be smart enough to share some of the benfits with the significant electorates and prevent their envy.
This might combine well with my Prussia idea above. The H.L. could then "rehearse" common political and military actions, and then put them into practice on a larger scale ...