0 votes
28 views

I have code where i want to redirect user to new path with a unique UD as soon as user hits root. (localhost:4200).

but i get this error

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'document/4fdb309b-df59-4da8-a32d-5265f7925bba'
Error: Cannot match any routes. URL Segment: 'document/4fdb309b-df59-4da8-a32d-5265f7925bba'

Below if my router module code segment .

import { v4 as uuidv4} from 'uuid'

const routes : Routes = [
  {path : '', redirectTo : '/document/'+uuidv4(), pathMatch: 'full'},
  {path : 'documents/:id', component: DocumentComponent}
]

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule {

 }

Not sure whats wrong !

Source Author: Steve Lennon

by (1.4k points)   | 28 views

1 Answer

0 votes

You can not declare dynamic route path. uuid4() will generate different uuid every time and you don't have those many components mapped to routes. you may want uuid as a route parameter as well. change first route to following and see if it helps.

{path : '', redirectTo : '/document/:'+uuidv4(), pathMatch: 'full'},

Credit to: Kshitij

by (2.2k points)  

Related questions

0 votes
1 answer
+2 votes
0 answers
asked Jun 17, 2020 by noor (1.1k points) | 35 views
0 votes
0 answers
+3 votes
1 answer
asked Mar 30, 2020 by toheed (1.4k points) | 68 views
+1 vote
1 answer
+2 votes
0 answers
+3 votes
0 answers
0 votes
1 answer
Welcome to Givemeans.net here you can ask questions and get the answers from other members of the community.
143 questions
123 answers
43 comments
159 users