#Regarding paths in routes
44 messages · Page 1 of 1 (latest)
Generally path: '' without pathMatch: 'full' is an error
I was thinking that because the docs say it matches from left to right and as soon as it finds a match it goes there
how come other paths do work for me though? i'd expect them to always take me to home page
Right now, every path matches the first HomeComponent. And you don't have a redirect (visible in your code) so I don't know how a redirect could happen.
g!badeyes @potent veldt Post code as text please
@potent veldt Please do not post pictures of code (especially photos of a physical screen) as they are difficult to read and difficult to correct (as you cannot copy code from a screenshot to modify it).
Angular Router's path matching is a little smarter than it claims. But still you should be clear about what you want to have. Which means properly decorating and ordering your routers.
that is what the last option is for according to the tuto
Yes, because ** assigns that router to the component: HomeComponent
There is no point in putting pathMatch: 'full' on path: '**'
g!toh @potent veldt Maybe you should do the official tutorial instead of one that is wrong or confusing you.
@potent veldt The place we recommend starting your Angular journey is with the Tour of Heroes tutorial, located here https://angular.io/tutorial.
Post the routes as text please
There are no redirects in your code. No redirects happen at all
const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'members', component: MemberListComponent },
{ path: 'members/:id', component: MemberDetailComponent },
{ path: 'lists', component: ListsComponent },
{ path: 'messages', component: MessagesComponent },
{ path: '**', component: HomeComponent, pathMatch: 'full' },
];
got it
There are no redirects in your code. No redirects happen at all
Unless you've done something terrible in your code.
so am I correct that the first option I can get rid of?
const routes: Routes = [
{ path: 'lists', component: ListsComponent },
{ path: 'members', component: MemberListComponent },
{ path: 'members/:id', component: MemberDetailComponent },
{ path: 'messages', component: MessagesComponent },
{ path: '', pathMatch: 'full', component: HomeComponent },
{ path: '**', redirectTo: '/' },
];
const routes: Routes = [
// { path: '', component: HomeComponent },
{ path: 'members', component: MemberListComponent },
{ path: 'members/:id', component: MemberDetailComponent },
{ path: 'lists', component: ListsComponent },
{ path: 'messages', component: MessagesComponent },
{ path: '**', component: HomeComponent /*, pathMatch: 'full' */ },
];
This would be the typical way to set that up ☝️ But what you are doing is non-standard.
const routes: Routes = [
{ path: 'home', component: HomeComponent },
{ path: 'lists', component: ListsComponent },
{ path: 'members', component: MemberListComponent },
{ path: 'members/:id', component: MemberDetailComponent },
{ path: 'messages', component: MessagesComponent },
{ path: '', pathMatch: 'full', redirectTo: '/home' },
{ path: '**', component: PageNotFoundComponent },
];
If you want to be different then this would be better I think
ah I see, I was just looking at tour of heroes
what would be "standard" then
yours looks like the tour of heroes example
const appRoutes: Routes = [
{ path: 'crisis-center', component: CrisisListComponent },
// { path: 'heroes', component: HeroListComponent }, // <-- delete this line
{ path: '', redirectTo: '/heroes', pathMatch: 'full' },
{ path: '**', component: PageNotFoundComponent }
];
I believe this is more typical standard: #1049365652609187881 message
oh I see, when you said "if you want to be different" you meant my post not yours right above your post. So your post is the standard way correct?
assuming you mean #1049365652609187881 message
yes IME
Got it. Sorry when I click on the link it doesn't paticularly highlight the message. I guess it just centers it.
thank you
Now I'm hesitant to continue this tutorial. It's a dotnet angular tutorial. Can you recommend any tutorials?
just the angular.io one. Link to that tutorial?
A practical example of how to build an application with ASP.NET Core API and Angular from start to finish
full code is here https://github.com/trycatchlearn/datingapp/
Final result seems better
https://github.com/TryCatchLearn/DatingApp/blob/main/client/src/app/app-routing.module.ts
But still think they have not the greatest routes implementation
Ok. Well I'll just review docs and compare every now and then.