Update
The problem seems to be appearing with Angular 16 standalone components since there is no ngModule. To be specific, when the i run ng build
the files are generated. Now i run the index.html file on vscode live server which opens the default route (http://127.0.0.1:5500/).
If i go to http://127.0.0.1:5500/search by typing in search bar. It doesn't work. or if i open this link in incognito tab. So what modification should i do to access it independently.
Reference code - Code
Old question
I have ecom website where I'm serving two different ui versions for large and small devices.
I am able to do that using angular routing file. I can access search route by localhost:4200/search
in development mode.
When i do ng build
the search route is not accessible.
FYI -
- Using angular 16 standalone components
- Tried using pathMatch:'full'
- Reason for having all components as children for MainComponent - MainComponent has header and footer common for all pages.
import { Routes } from '@angular/router';
export const routes: Routes = [];
export function getRoutes(): Routes {
// if (window.innerWidth < 768) {
// return [
// {
// path: '',
// loadComponent: () => import('./components/small/home/home.component').then(mod => mod.HomeComponent),
// },
// {
// path: 'profile',
// loadComponent: () => import('./components/small/profile/profile.component').then(mod => mod.ProfileComponent),
// },
// {
// path: 'wishlist',
// loadComponent: () => import('./components/small/cart/cart.component').then(mod => mod.CartComponent),
// },
// {
// path: 'cart',
// loadComponent: () => import('./components/small/wishlist/wishlist.component').then(mod => mod.WishlistComponent),
// }
// ];
// }
// else {
return [
{
path: '',
loadComponent: () => import('./components/large/main/main.component').then(mod => mod.MainComponent),
children: [
{
path: '',
loadComponent: () => import('./components/large/home/home.component').then(mod => mod.HomeComponent),
},
{
path: 'search',
loadComponent: () => import('./components/large/search/search.component').then(mod => mod.SearchComponent),
},
{
path: 'profile',
loadComponent: () => import('./components/large/profile/profile.component').then(mod => mod.ProfileComponent),
},
{
path: 'wishlist',
loadComponent: () => import('./components/large/wishlist/wishlist.component').then(mod => mod.WishlistComponent),
},
{
path: 'cart',
loadComponent: () => import('./components/large/cart/cart.component').then(mod => mod.CartComponent),
}
]
}
];
// }
}