Comments (14)
Right now, it's not supported. It looks easy to add though and could be useful indeed.
Can you give me a real life use case for it?
Also, would it be fine if it was mandatory that the rest path segments be the last ones? This is required to prevent conflicts.
With the current version of abyssa, the workaround would be to create 3 states and have two of them immediately redirect to the first one.
from abyssa-js.
Hi,
Say I'm supporting 10 apps. I am looking to define as few routes as possible as over time, each app may require route maintenance. I may try to be very general at first with something like
app1/:params*
app2/:params*
...
app10/:params*
or even
:app/:params* (I don't think this is currently supported)
As routing / application use cases get better defined as the apps evolve, I may try to define more, but I want initially to have the most general use cases and fewest routes possible so that I have flexibility down the road to fine tune and build out the stateful routing use cases appropriately.
If I start with 30 routes or so initially and need to make updates, that's a lot more maintenance across the routes and applications.
Does this make sense? I would be happy to get rest path segments in any fashion. Ultimately, I'm looking for flexibility in defining less routes in whatever way possible. I think less State definitions will be easier to maintain.
Thanks,
Mark
from abyssa-js.
Yes that makes sense. I want to tackle a rather fundamental refactoring first but I should be able to add this shortly after. Thanks for the suggestion.
from abyssa-js.
So, new State('app/:rest*')
would match
app/param1 AND
app/param1/param2 AND
app/param1/param2/param3
and in the enter
handler of that state, we would get the usual params object with a rest
property of either param1
, param1/param2
or param1/param2/param3
. Is this truly workable?
from abyssa-js.
Hi,
Sorry the lag, I was away. Yes, if 'rest' could contain 'param1', 'param1/param2', 'param1/param2/param3', that would work well.
The consumer of the route (me) would have to parse the parameters further for routing specific needs. I think this is similar to how Crossroads works. I'm not suggesting Crossroads behavior needs to always be matched, but here it seems like a decent reference.
from abyssa-js.
@saunders99999 You may factor out the States of your sub-applications and require them in your root application (if you know the sub-apps location relative to the root app). The Abyssa demo works that way.
@AlexGalays I think more important feature is to be able to add/remove the Router states in runtime after the router has been initialized. That would allow the self-contained components to construct States on the fly when they become available to the user (e.g. when they are lazy-loaded).
A real application example is a lazy-loading wizard (a dialog with steps). The application controller may not know all the wizard's States during the Router initialization because the wizard is not yet loaded.
from abyssa-js.
@sompylasar I think it's a different issue. It looks like @saunders99999 simply wants to have less boilerplate/duplication when declaring many states that (at least at first) have similar logic.
Lazily loading code and states could be interesting for big apps. I thought locking the state tree at router init was a good idea at the time because it was easier to reason about a final state tree than a partial one that can change later. Can you perhaps create a new issue for that?
from abyssa-js.
@AlexGalays Done. #21
As far as I understood, less boilerplate for @saunders99999 would be having some of the States abstracted and reused across applications.
from abyssa-js.
FYI, #21 is a different feature request. Matching multiple parameters and dynamically updating states after init are two separate feature requests. I think both have value and give quite a bit of flexibility to end users.
from abyssa-js.
Yes, I think I like both :)
from abyssa-js.
Does this test make sense and cover your use case?
asyncTest('rest params', function() {
var lastParams;
var router = Router({
index: State(),
colors: State('colors/:rest*', function(params) {
lastParams = params;
})
}).init('');
whenSignal(router.changed)
.then(goToColors)
.then(wentToColorsOk)
.then(goToColors2)
.then(wentToColors2Ok)
.then(goToColors3)
.then(wentToColors3Ok)
.done(start);
function goToColors() {
router.state('colors');
}
function wentToColorsOk() {
return nextTick().then(function() {
strictEqual(lastParams.rest, undefined);
});
}
function goToColors2() {
router.state('colors/red');
}
function wentToColors2Ok() {
return nextTick().then(function() {
strictEqual(lastParams.rest, 'red');
});
}
function goToColors3() {
router.state('colors/red/blue');
}
function wentToColors3Ok() {
return nextTick().then(function() {
strictEqual(lastParams.rest, 'red/blue');
});
}
});
from abyssa-js.
@AlexGalays, yes, that matches the use case I outlined and makes sense. The matching extends as far as 'red/blue', but seems like the test will also work with 'red/blue/green/yellow/orange/indigo' ...
Looks good to me.
from abyssa-js.
Should be fixed in ec965c1
I will release once I see the tests passing.
from abyssa-js.
Thanks for the updates...
from abyssa-js.
Related Issues (20)
- Redirect HOT 2
- `Router.init` should take state params HOT 1
- When a param owned by the child-most state changes, whole state tree is exited and re-entered HOT 1
- tagging v3.0.0 HOT 1
- Cannot override data HOT 2
- tag 4.2.0 release HOT 2
- enterPrereqs/exitPrereqs are fundamentally broken HOT 1
- Add/remove States at after Router init HOT 5
- bump q version to 1.0.0 HOT 4
- Customize hashbang HOT 2
- Relative navigation HOT 1
- Reusing the same state HOT 3
- Reflexion about StateWithParams HOT 4
- Update and diff params HOT 10
- Support base url HOT 1
- Exiting all states when changing a query param HOT 4
- NotFound exception thrown when State has enter, exit and sub State HOT 10
- Vdom and Abyssa HOT 6
- Modernize build and tests
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 abyssa-js.