Giter Club home page Giter Club logo

Comments (6)

millermedeiros avatar millermedeiros commented on July 20, 2024

I thought about it as well, but since on RegExp the ? is only referent to previous char or group than I thought it would be a better idea to have a separate token.

/foo? bar/;    // matches "foo bar" and "fo bar"
/(foo?) bar/;  // matches "foo bar" and "fo bar"
/(foo)? bar/;  // matches "foo bar" and " bar"

note that the ? is outside the group when the group is optional..

also see issue #33 (query string support), it will start getting too complex and will cause more confusions than it solves. BTW : and {} are invalid char in the middle of an URI (: is reserved for the protocol/port) and {} is forbidden without being escaped (RFC 3986)

from crossroads.js.

koistya avatar koistya commented on July 20, 2024

One more thing.. wouldn't it make sense to have a route always be a String in addition to which you could optionally add constraints. For example:

.addRoute('articles/{date}_{title}', { date: '\d{4}-\d{2}-\d{2}', title: '[\w_]+'});
.addRoute('products/{category}', { category: 'books|dvds'});

This way it shouldn't be a problem using optional parameters like this:

.addRoute('{controller}/{action}/{id?}')

Another convention could be:

// {id*} matches the rest of the path including / symbols
.addRoute('{controller}/{action}/{id*}')

You could also specify a delegate instead of regex for constraints:

.addRoute('products/{category}', { category: function(c) { $.ajax(..) or whatever } })

from crossroads.js.

koistya avatar koistya commented on July 20, 2024

Also I think users shouldn't worry about query strings and hashes (#bla-bla), if there are any routing tool should handle them for you automatically. For example:

.addRoute('{controller}/{action}', function(controller, action, queryString} { .. });

from crossroads.js.

millermedeiros avatar millermedeiros commented on July 20, 2024

you can kinda do what you want on the constraints:

var route = crossroads.addRoute('/articles/{date}_{title}');
route.rules = {
  date : /\d{4}-\d{2}-\d{2}/,
  title : /[\w_]+/
};

It allows RegExp, functions or an Array...

I find that the validation rules are less common than adding a listener to the route, that's why it isn't the second argument of addRoute().

also in some cases you may not need to validate one of the segments and/or you might need need to validate the string as a group, I decided that an object would be more flexible, see the example on the documentation for a complex use case.

There is also the option to pass the route as an RegExp instead of a String.

About query string and hashes there is already a feature request for it, see #33. (the first comment has an example on how to implement it on the current version), the problem with automagical approaches is that they are less flexible (eg, a query string inside the hash, order of arguments, etc...)

I created a new issue asking only for the {id*} (#43) - it's easier to track individual issues than a single thread with lots of things..

from crossroads.js.

millermedeiros avatar millermedeiros commented on July 20, 2024

forgot to say, you have the option to set a route as an RegExp only because in some cases it might be easier and it doesn't affect crossroads complexity (in fact it's simpler since the patternLexer can skip some steps).

from crossroads.js.

millermedeiros avatar millermedeiros commented on July 20, 2024

I'm going to close this issue for now, please post feature requests as individual issues that way I can reference them in commits, create branches that implement each feature, etc.. I've been very busy lately so not sure when I will have time to implement new features (specially the ones I don't need at the moment). Will try to release v0.8.0 next month and it should include most of the stuff listed on the issue tracker right now. thanks for the feedback and features suggestion.

from crossroads.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.