I have a theory-
World War 3 caused the dissolution of the UN. Instead of two major victors(like ww2), there was one, and during the process of signing a long lasting peace, United Earth proponents took advantage of the widespread public support they now had, and a new more powerful UN(UE) was formed. Things looked optimistic for a few years, but after First Contact, an alliance of eastern nations rejected the UE, withdrew, and incidents like that seen in Encounter at Farpoint happened there. Universal peace on paper wouldn't bring instant safety and security to the whole world.
It took until the mid 22nd century for the UE to regain full membership, which was aided by the fact that Humans were leaving Earth to colonize the galaxy, new technologies were being discovered, a new space age economy began to thrive, and independence as a nation state became less relevant. A UE may not have been possible, but for the opening up of space travel to other worlds.
World War 3 must have been a fight between globalists and antiglobalist nations. I just can't see it being an old fashion war of territorial dominance, even for the whole world. Anyways, the globalists won.
The nation states definitely continue to exist, possibly even in the TNG era, but they are like the core provinces of the Roman empire in late antiquity. They still have different cultures, native languages, and countries, but they're totally romanized, speak Greek or Latin(or both), are Roman Citizens, and consider themselves "Roman" first. Likewise for the United Earth and its many nations.