Issue with router default redirect to "second" route pattern of other route

I have a route config that “semantically” looks like this:

[ 
	{ redirect: "Go/To/Second", route: "" },
	{ moduleId: "modules/go-to-module", name: "GoToModule", "route": [ "Go/To/First", "Go/To/Second" ] } 
]

But when I start my app I arrive at /Go/To/First.

A. How can I make my start redirect go to /Go/To/Second while at the same time links set with route-href="route: GoToModule" should go to /Go/To/First?

B. On another note; Is it possible to use route-href in a way that gets me a link that goes to /Go/To/Second?

2 Likes

You want to split your second route into two separate routes so that you can use them differently and independently.

config.map([
  { route: "", redirect: "second" },
  { route: "first", name: "first", moduleId: "view-model"  },
  { route: "second", name: "second", moduleId: "view-model" },
])

See this working example: https://gist.run/?id=040775f06aba5e955afd362ee60863aa

For this simple example that is obviously a solution, but in my actual solution it’s a bit more complex.

Perhaps I have misunderstood the use of setting route to an array, so let me rephrase my question;

What is a legitimate use case of setting the route in the route map to an array of patterns? Why is it possible at all?

Under the hood, an array of patterns is actually expanded into multiple routes with the same properties.

So this:

[ 
  {
    moduleId: "modules/go-to-module",
    name: "GoToModule",
    route: [ "Go/To/First", "Go/To/Second" ]
  } 
]

Is equivalent to this:

[ 
  {
    moduleId: "modules/go-to-module",
    name: "GoToModule",
    route: "Go/To/First"
  },
  {
    moduleId: "modules/go-to-module",
    name: "GoToModule",
    route: "Go/To/Second"
  } 
]

It’s nothing more than an easy shorthand if you don’t need the functionality that unique names provide.

Routes are indexed by their name. Because the name property is the same, route-href is not able to tell them apart. That’s why you need to configure two separate routes with different names.

Legitimate use cases are any situation where you don’t need route-href (and perhaps something else I’m not aware of that needs unique names)