Routing

Routes map URLs to pages and functions. They're stateless: use them for anything that needs a stable URL.

@Override
public Routes routes() {
	return super.routes()
			.map( "/", FrontPage.class )
			.map( "/hello", () -> NGResponses.ok( "Hello!" ) )
			.map( "/products/*", this::productPage );
}

private NGActionResults productPage( NGRequest request ) {
	final String id = request.uri().substring( "/products/".length() );
	...
}

Targets

Target
Component classA new page instance per request
NGRequest -> NGActionResultsWhen you need the request
() -> NGActionResultsWhen you don't
NGRequestHandlerFull control

Matching

  • Exact, or a prefix when the path ends with *.
  • No named parameters (/products/:id) yet (#17), and no matching on the HTTP method.
  • Your routes win over the framework's, so mapping / replaces the welcome page.
  • If nothing matches, a file in src/main/resources/public with that path is served, otherwise a 404.
  • In development, routes are re-read on every request.

Reserved prefixes

Prefix
/no/Component actions
/na/Direct actions
/nr/Resources
/nd/Dynamic resources
/ng/Framework and development tools