The trade network is just that - a network.
In the same way that a city can be linked by road via another city already linked by road - they don't all need their own roads directly to the capital - your trade network will spread via harbours.
What this means is you need at least one harbour within each "sub network" of your trade network. Here is a quick diagram:
Continent A Water Continent B
|~ ~ ~ ~ ~ ~|
1------2 ~ ~ ~ ~ ~ 3------4-----5
|~ ~ ~ ~ ~ ~|
City 1
is your capital, and linked by road to city 2
. If city 2
and city 3
both have a harbour then they extend the trade route across the water, this means 4
and 5
are also connected, because they are linked to 3
and so, by proxy, use it's harbour link.
If in this example, even if 2
was your capital it would still need a harbour to extend your trade route accross the water, having a harbour in 3
alone is not sufficent.
This also works if 2
and 3
were on the same continent, but not connected by road/rail.
Regarding passing through another civ or city-states territory:
Trade routes can pass through other civs as long as you have open borders agreement from them. Trade routes do not work through a civ you're in war with, even though technically your units can pass within their borders.
Regarding city-states, it works of you are either friends or allied with them.
Regarding passing through an actual city:
I believe it's precisely the same as the above - your road passing through the actual city shouldn't make a difference, except for saving you money, since cities count as road tiles.
Best Answer
From your image I can tell two things:
You can tell that they are connected by looking at Shanghai. Right underneath the city name for Shanghai, there's a small black circle with three yellow dots . This icon means that you have a trade route with your capital city.
The reason you received a message that the trade route was broken, was most likely because you built a harbor in both cities. When you do so, the game changes your trade route from by land/road to by sea. It is a bit misleading because this "a trade route has been broken" prompt still comes up, and is technically correct, but in reality your trade route is just changing from via road to via sea.