Before around 1950x-1970x rail networks were more dense (at least in Europe) - any significant goods source/destination (like a warehouse, a factory e. t. c.) had a railway spur. Lots of rail tracks / spurs were abandoned /removed when it was widely believed that trucks are the future and railways are outdated.
If all these spurs were kept last mile problem would not be as bad for railways. Also electric trucks are well suited to solve this last mile problem.