As to the suggestion that this question has already been answered, that answer suggests a workaround solution that does not solve my use case.
The answer referenced suggests using 2 routes, hence the title of my question which stipulates without having to to define a second route Using 2 routes creates a problematic browser history.
If avoidable, I do not want to use a query string parameter or hash.
I do not want to use a child route because that would require the use of a secondary router outlet, which will add a level of complexity to my application that I have to believe is avoidable.
My route has 2 parameters, one being optional. It is a lazy loaded route, but I assume this should not matter as it relates to my question. If it does matter please let me know.
The route:
{ path: 'list/:name/:type', loadChildren: './list/list.module#ListModule'},
The :name
parameter is required for this route to load correctly, but the :type
parameter is optional.
I tried defining 2 separate routes and setting both to point to the same component, one with the parameter and one without, but this is not a working solution in my case.
I'd like the browser's history to be correct and reflect the addition of, or update to the optional :type
parameter via user interaction without requiring navigation to another route causing the component to reload.
So, it is the initial route entry that is the problem. Once the :type
parameter has been defined the first time, subsequent changes would not require a route change.
I'd like to ask, specifically, is it possible to define an optional parameter for a route in Angular?
Or, as a solution to this problem, is it possible to update the route / URL after the route has instantiated without triggering navigation?