Most likely you would like to create a separate MapData object for processing such data. There is a nice tool osmfilter that allows to filter out specific route types before importing data to Julia.
In this way you can have separate representations of your map data.
However, if you want to operate directly on the MapData object you could set the distance weights to Inf and which would force the routing algorithm to avoid such edges or return Inf route length.
Suppose you have the map from the tutorials:
using OpenStreetMapX, Graphs
map_file_path = joinpath(dirname(pathof(OpenStreetMapX)),"..","test/data/reno_east3.osm")
mx = get_map_data(map_file_path, use_cache=false);
Than you could do to filter out secondary routes:
m2 = deepcopy(mx)
edgs = collect(edges(mx.g))[findall(!=(4), mx.class)]
setindex!.(Ref(m2.w), Inf, src.(edgs), dst.(edgs))
Now the selected route will differ between mx and m2:
julia> shortest_route(mx, 3073938243, 3101115892)
([3073938243, 3073938154, 140340636, 140340638, 3101117891, 3101115892], 549.9261168024648, 32.32592992211371)
julia> shortest_route(m2, 3073938243, 3101115892)
([3073938243, 140533189, 140533195, 3101115892], 617.4395184717641, 54.94654519330738)