routify icon indicating copy to clipboard operation
routify copied to clipboard

URL in navigation works - goto not

Open Tommertom opened this issue 3 years ago • 5 comments

See repo - https://github.com/Tommertom/svelte-ionic-app/tree/2.ListStarter

Component AppMessage.svelte uses a $goto to go to route "message/3"

https://github.com/Tommertom/svelte-ionic-app/blob/2.ListStarter/src/components/AppMessage.svelte

Entering the full URL in the address bar works, a goto to the same doesn't - error "could not find destination node message/3"

Route /message is located in folder message with [id].svelte as receiving end.

https://github.com/Tommertom/svelte-ionic-app/tree/2.ListStarter/src/routes/message

Tommertom avatar Jun 23 '22 02:06 Tommertom

$url("/message/[id]", { id: "5" }) does show the message/5 url, so it is a valid route in the db. But then it ends here...

Tommertom avatar Jun 23 '22 13:06 Tommertom

Hi @Tommertom. Does $goto("/message/[id]", { id: "5" }) work?

jakobrosenberg avatar Jun 23 '22 14:06 jakobrosenberg

$goto("/message/[id]", { id: "5" })

Like a charm!

Tommertom avatar Jun 23 '22 15:06 Tommertom

So does this mean a goto with full path is not supported as way to change route? Was it my thinking, or something that worked in Routify2 -right? Then at least, it might be worthwhile mentioning in the documentation.

And if it is not intended this way, then this issue imho turns into a feature request with high prio.... Other routers support full path as input.

So not sure if I concur with a "solved" label.

And to be honest, I need to look at mycode, because I have an app in r3 which does allow full path, and this one doesn't - while it is a direct copy. I am confused.

Tommertom avatar Jun 23 '22 18:06 Tommertom

Goto with a full path would just be an alias for the native history.pushState.

That said, the next patch may include an option that allows the use of a compiled path. The work has already been done for node.traverse(path, allowDynamic) where the second parameter enables compiled paths.

For URL helpers like $url and $goto, the solution might be

$<helper>(path, params, options)

So in your case it would be like this pseudo code $goto('/some/path', {}, { dynamic: true }).

jakobrosenberg avatar Jun 24 '22 09:06 jakobrosenberg