Comments (6)
crossroads already have a method called create
so this method should have a different name.
when I was starting crossroads development I considered adding id/name to each route but I thought it would be redundant in most cases (I never really needed it) but maybe we should add a new method to get the route by id and add a new method to the Route itself to trigger it - keeping ID as an optional property (use the route pattern as id if not present), e.g:
crossroads.addRoute('/news/{id}', showNews);
var r = crossroads.addRoute('/projects/{id}/:name:', showProjectDetail);
r.id = 'projects';
// get route by ID
crossroads.getRoute('projects').trigger({id:123, name:'foo-bar'});
//can get route by pattern (maybe only if it doesn't have an ID)
crossroads.getRoute('/news/{id}').trigger({id:15});
Issue #34 is also related.
PS: I probably won't have time to implement it till next year (if I do)
Thanks for reporting.
from crossroads.js.
it's important to remind that I'm not a huge fan of using strings since it can lead to bugs that are hard to track.. I would recommend you to keep references to every Route you may need to call and create a new method for each one of them, e.g.:
// keep route as a private variable
var projectsRoute = crossroads.addRoute('/projects/{id}');
...
// than expose a method on your API
myNamespace.goToProjects = function (paramObj) {
projectsRoute.trigger(paramObj);
};
another option is to expose all the routes directly:
myNamepace.routes = {
projects : projectsRoute,
news : newsRoute
};
//than you can do later
myNamespace.routes.projects.trigger({id:123});
This means that the getRoute()
method may never ship in crossroads while trigger()
is a very strong candidate.
from crossroads.js.
just got back to this feature request and realized that I forgot to add the simplest way to "trigger" a route, since the matched
is simply a Signal
you can dispatch
is at will:
var route = crossroads.addRoute('/foo/{bar}', function(id){
console.log(id);
});
route.matched.dispatch(123);
you can also dispatch the crossroads.routed
signal if needed.
from crossroads.js.
Cool, many thanks
from crossroads.js.
Ignoring this feature request since user can dispatch route.matched
signal if needed. To do it properly would require validating each argument to see if it matches the route.rules
. It would be also strange to dispatch the crossroads.routed
signal if it really didn't routed anything (it was triggered manually), so I think it's better to keep this feature out to avoid confusions.
I should add route.interpolate()
(#34) in the next release so it will be easy to call crossroads.parse
passing the proper string like this:
var route = crossroads.addRoute('/foo/{id}');
var req = route.interpolate({id: 123}); // "/foo/123"
crossroads.parse( req );
Cheers.
from crossroads.js.
@milworm route.interpolate()
just landed on v0.9.0, cheers.
from crossroads.js.
Related Issues (20)
- routes with query params HOT 2
- How to use routing libraries like crossroads js with preload js?
- Non-encoded slashes (/) on query params choosing wrong pattern
- Why do `setting window.location.hash` and `hasher.setHash` result in different behavior of question mark `%3F`?
- URL param names are lost : route handler should get param object with names as fields
- Route Losing Reference After First Call HOT 1
- Best way to detect param changes in the same route
- Bower update failing HOT 3
- test
- Support of native URLs HOT 2
- Support of wildcard in the beginning of the URL HOT 2
- destroy function HOT 1
- Getting params as one object not on callback arguments HOT 1
- Is this project still alive? HOT 5
- Trailing slashes are appended to routes that have query params HOT 1
- Empty url in rules
- Crossroads - 404 on route HOT 1
- Nested routes
- [ SUGGESTION ] .routed.addBefore() and .routed.addAfter()
- Unmatched routes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crossroads.js.