title: Allowing routes with and without {culture} (.net core 2.2)
body: <p>UPDATE: I got it working - added the following to the routes:</p>
  
  <p>[Route("{culture}/[action]")]</p>
  
  <p>[Route("/[action]")]</p>
  
  <p>Problem is now when I am on /da/about it won't add the /da/ to the links generated on the AnchorTagHelper. </p>
  
  <hr>
  
  <p>Trying to allow culture in the routes. But I also want it to work without (fallback to english).</p>
  
  <p>domain.com/en/about</p>
  
  <p>domain.com/about</p>
  
  <p>I can only get one of them to work at one time. Adding / removing the {culture} makes it work for each.</p>
  
  <p>[Route("{culture}/about")]</p>
  
  <p>Have tried changing, moving etc. everything with the MapRoutes</p>
  
  <p>Any ideas how to catch both routes?</p>
  
  <p>I have the following code:</p>
  
  <pre><code>services.Configure&lt;RouteOptions&gt;(options =&gt;
              {
                  options.ConstraintMap.Add("culture", typeof(LanguageRouteConstraint));
              });
  </code></pre>
  
  <p>--</p>
  
  <pre><code>services.AddLocalization(options =&gt; options.ResourcesPath = "Resources");
              services.Configure&lt;RequestLocalizationOptions&gt;(options =&gt;
              {
                  var supportedCultures = new List&lt;CultureInfo&gt;
                  {
  
                  new CultureInfo("en"),               
                  //new CultureInfo("da-DK"),
                  new CultureInfo("da")
               };
                  //options.DefaultRequestCulture = new RequestCulture(DefaultCultureName, DefaultCultureName);
                  options.DefaultRequestCulture = new RequestCulture(culture: "en", uiCulture: "en-US");
                  options.SupportedCultures = supportedCultures;
                  options.SupportedUICultures = supportedCultures;
  
                  options.RequestCultureProviders.Insert(0, new RouteDataRequestCultureProvider { Options = options });               
              });
  </code></pre>
  
  <p>--</p>
  
  <pre><code> app.UseMvc(routes =&gt;
                  {
                      routes.MapRoute(
                              name: "LocalizedDefault",
                              template: "{culture:culture}/{controller=Home}/{action=Index}/{id?}");                
                      routes.MapRoute(
                            name: "default",
                            template: "{controller}/{action}/{id?}",//"{*catchall}",
                            defaults: new { controller = "Home", action = "Index" });                 
                  });
  </code></pre>
  
  <p>--</p>
  
  <pre><code>public class LanguageRouteConstraint : IRouteConstraint
  {
      public bool Match(HttpContext httpContext, IRouter route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection)
      {
          if (!values.ContainsKey("culture"))
              return true;
  
          var culture = values["culture"].ToString();
          return culture == "en" || culture == "da";
      }
  }
  </code></pre>