A communication method includes a first network device obtaining a first route and a second route from a second network device. A first network segment corresponding to the first route is a subnet segment of a second network segment corresponding to the second route. The second route is an aggregated route, and the first route indicates that the first network segment is unreachable. The first network device switches a next hop of the aggregated route based on the first route.