Error: Cannot match any routes. URL Segment: 'submit'

Error: Cannot match any routes. URL Segment: 'submit'



I'm trying to navigate from one component to another, but nothing is working for me. I've tried routerLink as well, but it didn't work too.



Below is my explore.components.ts file:


import Component, OnInit from '@angular/core';
import Router from '@angular/router';

@Component(
selector: 'app-explore',
templateUrl: './explore.component.html',
styleUrls: ['./explore.component.css']
)

export class ExploreComponent implements OnInit

constructor(private router: Router)

ngOnInit()


onClick()
this.router.navigate(['/submit']);




This is my explore.html file. A click on the button is supposed to display the "submit" component.


<button type="button" class="btn" (click) = "onClick()">Click here to submit your work <i class="fa fa-hand-peace-o fa-lg"></i></button>



Both the components are children of the app component.





sth is wrong with your routes, show them in the question
– maha
Sep 2 at 9:10





const ROUTES: Routes = [ path:'', component: HomeComponent, path:'sign-up', component: SignUpComponent, path:'login', component: LoginComponent, path:'contact',component:ContactComponent, path:'explore', component:ExploreComponent ] (in app.module.ts)
– Nikita
Sep 2 at 11:11






you don't have a route called submit !
– maha
Sep 2 at 11:14





that's because I'm going from explore component to submit component, and not from app component to submit component. ?
– Nikita
Sep 2 at 11:16




2 Answers
2



try it now:


const ROUTES: Routes = [ path:'', component: HomeComponent,
path:'sign-up', component: SignUpComponent,
path:'login', component: LoginComponent,
path:'contact',component:ContactComponent,
path:'submit',component: SubmitComponent,
path:'explore', component:ExploreComponent ]



you didn't have a route that navigates to the submit component you have, now you can navigate to it from any other component.



you should have something like yourcomponent-routing-module.ts or app-routing.module.ts



If you don' t have it, generate it using angular cli.


ng generate module SomeModule --routing (or ng g m SomeModule --routing, for short)



here is a sample routing module.the route is targeting https:yoursite/dashboard/mydashboardtypevalue


import NgModule from '@angular/core';
import Routes, RouterModule from '@angular/router';
import DashboardComponent from './dashboard.component';
import DashboardContainerComponent from './dashboard- container/dashboard-container.component';
import RequiredAuthenticatedUserRouteGuardService from '../shared/services/required-authenticated-user-route-guard/required-authenticated-user-route-guard.service';

const routes: Routes = [
path: 'dashboard',
component: DashboardComponent,
canActivate: [ RequiredAuthenticatedUserRouteGuardService ],
children: [
path: ':dashboardType', component: DashboardContainerComponent // this is a sample required parameter

],
];

@NgModule(
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
)
export class DashboardRoutingModule



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế