I have a route.
routes: {
"example/=q:query": "example_main"
}
This:
localhost/site/#example/q=hello
works perfectly but if the URL is:
localhost/site/#example/q=
My router does not understand it and no action is performed. Does anyone know how to fix this?
routes: {
"example/q=*query": "example_main"
}
Related
I have the following route structure
src/routes/[slug]/results
src/routes/[slug]/about
I can't figure out how to link to the routes in SvelteKit. The routes themselves work when I access them through the browser navigation bar.
How can I create a simple links on the [slug] page, that will link to the child routes?
Both below link to the root:
results
results
Tried something like below, but that didn't work.
results
results
I assume it's something similar, but the SvelteKit documentation on routing and advanced routing don't mention anything related to navigation within dynamic routes.
Would just add the parameter to the link:
<script>
import { page } from '$app/stores';
</script>
Results
I figured it out, it was a bit hidden in the documents (and I'm a starter, so not fully aware of all the concepts yet).
In +page.js:
/** #type {import('./$types').PageLoad} */
export function load({ params }) {
return {
slug: params.slug
};
}
In +page.svelte:
<script>
export let data;
</script>
results
share
I think I'm missing something basic but I can't find out what, I've checked other post on this topîc but couldn't find a clear answer.
The url launching my app is:
http://local.myapp.ngx:8080/myapp/fileasset/app.html
app.html is loading require/main.js
// MAIN.JS
initializing the router:
new Router();
starting history:
Backbone.history.start({
pushState: true,
root: "/myapp/fileasset/"
});
// ROUTER.JS
routes: {
'':'test'
}
==> PROBLEM , test function is never called.
if I try this:
routes: {
'*wtv':'test'
}
==> THEN "test" is triggered but how to catch other routes ?
thanks for your help !
Indeed it was a really really basic thing, I didn't put the right root
root: "/myapp/fileasset/ui.html"
This should be super basic but I can't get routing working. I should mention that the application is located in a subdirectory called /dist/. Here's my code:
var QuestionRouter = Backbone.Router.extend({
routes: {
"/dist/" : "startTest"
"dist/:id": "getModel"
},
startTest: function(){
console.log('home called')
},
getModel: function(){
app.getModel(id);
}
});
var app = new QuestionView;
var appRouter = new QuestionRouter;
Backbone.history.start({pushState: true});
The URL to trigger this route is:
www.example.com/dist/
www.example.com/dist/12345
Any help would be appreciated.
You'll need to use # (hash symbol).
Backbone routers are used for routing your applications URL's when
using hash tags(#)
This is a quote from a Backbone tutorial: What is a router?
See Backbone's Router documentation
Then your routes would be:
www.example.com/#/dist/
www.example.com/#/dist/12345
You can also use Backbone routes without hashes.
Ok So I was able to work this out:
My route hash should look like this:
routes: {
"" : "startTest",
":id": "getModel"
}
I had to remove pushState: true, with this in place the route wasn't being triggered, not sure why:
Backbone.history.start();
In Backbone.Marionette documentation some statement puzzled me:
You can also add standard routes to an AppRouter with methods on the router.
(https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.approuter.md)
How it might look like in reality?
You can add a route on the AppRouter and define the method to handle it in either the router or controller.
MyRouter = Backbone.Marionette.AppRouter.extend({
// "someMethod" must exist at controller.someMethod
appRoutes: {
"some/route": "someMethod"
"yet/anotherRoute": "routerMethod" // app router route
},
/* standard routes can be mixed with appRoutes/Controllers above */
routes : {
"some/otherRoute" : "someOtherMethod"
},
// method on the router
routerMethod: function() {
// ...
},
someOtherMethod : function(){
// do something here.
}
});
I have the following routes object:
routes: {
"*defaults": "home",
'#test': 'test'
}
Here's the url options:
myApp.html // home is called as desired
myApp.html#test // home is called instead of test
What did I miss?
Per the docs, you don't need the hash mark in the route (that's implied by the Backbone routing convention). Also, the "*defaults" route is going to catch everything, so you should put it last after more specific routes. So, like this:
routes: {
'test': 'test'
"*defaults": "home",
}
Should result in myApp.html#test getting routed to test.