ngx-admin
ngx-admin copied to clipboard
Routing issue : inconsistent behaviour between app and pages
Issue type
I'm submitting a ... (check one with "x")
- [X] bug report
- [ ] feature request
- [ ] question about the decisions made in the repository
Issue description
Current behavior:
When trying to set some path to NotFoundComponent directly through app-routing.module.ts, it causes an infinite loading when trying to access this path. The same code works if put inside a submodule path (for example, pages, in pages-routing.module.ts). Absolutely no error is displaying in the console or anywhere.
Expected behavior:
Handle the request correctly and send the user to the NotFoundComponent. If something is wrong, display an error (for others errors in routing modules, we get errors displayed in the console)
Steps to reproduce:
See the Related code below. Basically, we put on app-routing L48 the code that is used on pages-routing L78.
Related code:
app-routing.module.ts NOT WORKING
[...]
{ path: '', redirectTo: 'pages', pathMatch: 'full' },
//{ path: '**', redirectTo: 'pages' }, // starter code : redirect all requests to pages
{ path: '**', component: NotFoundComponent, }, // new code : (try to) handle requests here
];
pages-routing.module.ts WORKING WELL
[...]
{
path: '',
redirectTo: 'dashboard',
pathMatch: 'full',
},
{
path: '**',
component: NotFoundComponent,
},
],
}];
Other information:
npm, node, OS, Browser
NPM: 6.14.16
Node: v14.19.1
Server (dev) running on Linux (WSL), client on Windows 10
Browser: Chrome
Angular, Nebular
Nebular: 8.0.0
Angular: 12.2.16
Any help to understand the issue will be appreciated 😄 I plan to use ngx-admin a lot and contribute, so I'm down to fix this, but I'm a bit stuck here 😅
Well...without knowing what you actually are trying to achieve...
When i set NotFoundComponent to app-routing i get an error message saying it is missing the nb-card, so maybe you forgot to do that?
Your url determines the module that handles the routing ** in the respective module. For example... if your URL has /pages in it ... pages-routing then that module will handle **. But if your url contains auth/ then auth-routing is going to handle **.
https://angular.io/guide/router -> "The last route with the path of ** is a wildcard route. The router selects this route if the requested URL doesn't match any of the paths earlier in the list and sends the user to the PageNotFoundComponent."
My uneducated guess is that NotFoundComponent in your app-routing will only be triggered when your URL does not match any routes defined in it. e.g. https://www.myapp.com/thishastomatcharouteorelseNotFound or https://www.myapp.com/pagesss
I hope you can make sense out of this because i am just awake and haven't had my coffee yet :)