Routing on tracks?

I’m currently doing a project with requires me to visualise tram routes on a map I’m using OSM with leaflet. I have the coordinates of the stops of every tram route, but there are sections of tracks, which go on one side of the road or there is no road near them. There doesn’t seem to be a option to follow tracks and my route map looks very strange. Is there a way to make it ignore roads and stick to tracks?

Here is an image of what I’m getting. The grey lines are the tracks.

What you’re looking for is public transit, which we’re not offering. Look at Mapbox, HERE or Google Maps for this.