dotvvm icon indicating copy to clipboard operation
dotvvm copied to clipboard

Generate a list of routes on build

Open tomasherceg opened this issue 7 years ago • 1 comments

The VS extension runs DotVVM Compiler to retrieve the configuration of the application, which includes a list of routes.

It would be nice to generate constants or helper methods for the routes, which could be used in the code:

public static class DotvvmRoutes {

    public static readonly DotvvmRouteDescriptor Home
         = new DotvvmRouteDescriptor("Home", "home");

    public static readonly DotvvmRouteDescriptor ProductDetail 
         = new DotvvmRouteDescriptor<ProductDetailRouteParameters>("ProductDetail", "product/{id}");
}

public class ProductDetailRouteParameters 
{
     public int Id { get; set; } = 0;
}

The DotvvmRouteDescriptor can contain the following methods and properties:

  • BuildUrl([params]) will build a virtual URL (starting with ~)
  • BuildUrl(basePath [, params]) will build an absolute URL
  • Name returns the route name
  • UrlTemplate returns the URL template

The file can be generated in the root of the web app, or to any other location specified in the dotvvm.json config file, or in the Dotvvm-specific CSPROJ parameters.

The only issue is that the app needs to be compiled and run to get the list of routes, which produces a new or modified C# file which will need another compilation to be run. Which is not such a big problem because the file changes only when the routes in the application change. But the tool should make sure that the file content is actually different and not just overwrite it.

tomasherceg avatar Jul 24 '17 17:07 tomasherceg

We are working on it. I am moving this issue to milestone 2.3.

quigamdev avatar Apr 06 '19 21:04 quigamdev