-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent navigation? #2
Comments
What's your code so far? |
Have'nt written anything yet, I was going through the docs |
By the sounds of it your trying lightrouter in a single page app? |
its actually a hybrid. Some parts mimic a single page app, some parts traditional. I thought I could run javascript code conditionally depending on the URL using lightrouters matching. |
You can easily do it with traditional path url, but if using in a single page app you would have to create a bit of additional code to listen for hashbang changes, run router, add to history if matching etc. Lots of other javascript routers are more 'heavy weight' and do all this for you, lightrouter is more of a foundation for matching paths and calling code conditionally. I have been meaning to create a plugin for light router to make it easier to integrate it will SPA out of the box, something definitely on the todo list. |
Yeah, actually, my focus is only running code based on a path on the traditional urls. No pushstate or hashbang sniffing. How can I achieve this? |
In which case it's very easy, the docs show exactly how to use the lightrouter. What part of the docs are you having trouble understanding? (Maybe needs improvement) |
Here is an example of what I want to achieve using another library called byroads(https://github.com/W3Max/byroads.js), I can declare a route, and then test if it matches. Navigation is not triggered.
I could not find an example that I could use for my case. |
It's technically possible to test if a specific route matches like that, but this router does it generally like: var router = new LightRouter({
type: 'path',
path: 'testing-xk500.jsptesting'
});
router.add(/^(.*)-xk([0-9]*).jsp(.*)/, function(params) {
console.log('matched', params);
});
router.run(); You don't need to supply |
If you wanted to test the routes manually you could do something like: var router = new LightRouter();
router.add(/^(.*)-xk([0-9]*).jsp(.*)/, function() { });
for (var i = 0; i < router.routes.length; i++)
{
console.log(router.routes[i].test('foo')); // false
} Or if your only testing one route: var router = new LightRouter({
type: 'path',
routes: {
'^(.*)-xk([0-9]*).jsp(.*)': function() { }
}
});
console.log(router.routes[0].test('foo')); |
Nice! Thanks |
I spoke to soon, the example below causes an error
The recursive call to "run" fails
|
This works
|
Are you running this in a browser/node? |
Browser, chrome and FF |
I suspect your using some other js that has prototyped arrays like Can you try using only lightrouter in your app and see if it works? |
I am actually using a shim lib(es5-shim.js) since we have to support older IE versions. But removing it does not help, same problem. |
If you clone this repository and open |
do I need anything else
|
Just open |
ok, all tests pass, sorry about the delay
|
Just pushed a new version, try 0.2.2 and let me know if it fixes your issue |
Ok,will do. Have you pushed it? The repo ist still showing an old commit |
Yeah I have pushed it, it's on tag 0.2.2 so should be able to pull it down. Master is showing as 2 commits behind, not sure why...... |
@kokujin just released new version, does this fix any issue you were having? |
@kokujin I've just released another version, you can match routes manually now with |
I would like lightrouter to detect the page that a user is on and allow me to run certain code blocks, is it possible to make lightrouter prevent navigation to a matched route?
Thanks!
The text was updated successfully, but these errors were encountered: