For the record: this is currently using the fairly new "@angular/router": "3.0.0-alpha.8" , the route definitions are at the bottom of the message.
When I try to navigate in my application, the behavior is different depending on whether I enter the URL directly or via a link:
- Works: Enter
http://localhost:9292 in the address bar, correctly go to http://localhost:9292/about - Works: Navigation directly to
http://localhost:9292/about via the address bar - Works:. If I go to
http://localhost:9292/about/projects using the <a> tag, in the context of the FrontComponent attribute and [routerLink]="['projects']" , the routing will work fine. Broken: Direct navigation to http://localhost:9292/about/projects leads to the following error message (abbreviated Stacktrace):
Unhandled Promise rejection: Cannot match any routes: 'projects' ; Zone: angular ; Task: Promise.then ; Value: Error: Cannot match any routes: 'projects' Stack trace: applyRedirects/<@http://localhost:9292/node_modules/@angular/router/apply_redirects.js:29:34 Observable.prototype.subscribe@http ://localhost:9292/node_modules/rxjs/Observable.js:52:57
What can I do wrong here? Is there a way to view all routes that were rejected in the error message?
Change , because it has been suggested many times now: I do not suspect that this is a server-side problem. Previous routing through router-deprecated worked fine, and the HTML served along the route looked just fine. But just in case, this is the appropriate server-side routing code ( ruby with sinatra ):
I do not suspect that this is due to incorrect route definitions (routing works by reference), but for completeness, these are routes:
front / front.routes.ts:
export const FrontRoutes : RouterConfig = [ { path: '', redirectTo: '/about', terminal: true }, { path : 'about', component: FrontComponent, children : [ { path: 'projects', component: ProjectListComponent}, { path: '', component: AboutComponent}, ] } ]
Editor / editor.routes.ts:
export const EditorRoutes : RouterConfig = [ { path: "editor/:projectId", component : EditorComponent, children : [ { path: '', redirectTo: 'settings', terminal: true}, { path: 'settings', component : SettingsComponent }, { path: 'schema', component : SchemaComponent }, { path: 'query/create', component : QueryCreateComponent }, { path: 'query/:queryId', component : QueryEditorComponent }, { path: 'page/:pageId', component : PageEditorComponent }, ] } ]
app.routes.ts:
import {EditorRoutes} from './editor/editor.routes' import {FrontRoutes} from './front/front.routes' export const routes : RouterConfig = [ ...FrontRoutes, ...EditorRoutes, ] export const APP_ROUTER_PROVIDERS = [ provideRouter(routes) ]