The thing I learned from the HIMYM Finale, it really is bad luck to see the bride in her wedding dress
More likely ted was 30 when she met the mother. 3 years they have been together and had 2 kids then got married. The mother got sick, lets say for a year then died. then 6 years after she got back with robin. Do the Math.
Season 7 Episode 17th “No Pressure”
Ted and Robin had an agreement to get married if they are both single at the age of 40.