redstone-dart / redstone

A metadata driven microframework for Dart.
http://redstone-dart.github.io/redstone
MIT License
342 stars 42 forks source link

A matcher for all routes with a path parameter #92

Closed danschultz closed 8 years ago

danschultz commented 9 years ago

I'm trying to define a route that matches everything, but also passes the path as a param to its annotated function. For example:

I tried the following, and it works for sub-paths, but fails on root /.

@app.Route("/:path*", responseType: "text/html", matchSubPaths: true)
String all(String path) => "Hello World";

Is this possible with Redstone?

cgarciae commented 9 years ago

What are you trying to accomplish? An Interceptor or route decorator plugin might what you need.

danschultz commented 9 years ago

I'm trying to write an isomorphic Dart app using React. I'd like Redstone to respond to any path, and pass the path into a React component which will handle the routing.

cgarciae commented 9 years ago

How about this?

@app.Route ('*', matchSubPaths: true)
anyPath () => app.request.url;

Matches any route and you can the path from the url.

danschultz commented 9 years ago

That works, but I also need access to the path in order to pass it into my server-side React component which is handling the routing. I tried the following, but I get a 404:

@app.Route(':path*', matchSubPaths: true)
anyPath(String path) => app.request.url;
cgarciae commented 9 years ago

Is this enough?

@app.Route ('*', matchSubPaths: true)
anyPath()
{
    var path = app.request.url;
    //Do something with path
}

The url IS the path.

luizmineo commented 9 years ago

The following example works fine in v0.6.0-beta.1

import 'redstone/redstone.dart';

@Route(":path*", responseType: "text/html")
String all(String path) => path;
danschultz commented 9 years ago

Sorry @cgarciae, I overlooked app.request.url. I'll give that and v0.6.0 beta a try.