Angular 2 Routes - Cannot Match Any Routes RC4 -
i testing basic angular2 app , ran trouble routing. stripped have 2 test components. project rc4 , built angular cli. had nightmares last night...it seems should easy figure out can't see it. feel has app being in src folder? (app not 'root'?)
thank help.
error (from chrome dev)
zone.js:461 unhandled promise rejection: cannot match routes: '' ; zone: angular ; task: promise.then ; value: error: cannot match routes: ''(…) zone.js:463 error: uncaught (in promise): error: cannot match routes: ''(…)
edit ***** fixed fixed doing few things. (1) added default route routes array in app.routes.ts.
project structure is
src app test.component.ts test2.component.ts app.routes.ts
app routes:
import { providerouter, routerconfig } '@angular/router'; import {test2component} './test2.component'; import {testcomponent} './test.component'; const routes: routerconfig = [ { path: '', component: testcomponent }, { path: 'test2', component: test2component } ]; export const approuterproviders = [ providerouter(routes) ];
testcomponent
import { component } '@angular/core'; import { router_directives } '@angular/router'; @component({ moduleid: module.id, selector: 'test-nav', templateurl: 'test.component.html', directives: [router_directives] }) export class testcomponent {}
testcomponent2
import {component} "@angular/core"; @component({ templateurl: "test2.component.html", }) export class test2component{}
html test component link
<a href="#" routerlink="/test2" routerlinkactive="active"><h1>test</h1></a>
error when click on link html zone.js:101 http://localhost:4200/test2.component.html 404 (not found)
index.html
<!doctype html> <html> <head> <base href="/"> <meta charset="utf-8"> <title>webstimate</title> <script src="https://code.jquery.com/jquery-2.2.0.min.js"></script> <script src="vendor/bootstrap/dist/js/bootstrap.js"></script> <link rel="stylesheet" type="text/css" href="vendor/bootstrap/dist/css/bootstrap.min.css"> <!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>--> {{#unless environment.production}} <script src="/ember-cli-live-reload.js" type="text/javascript"></script> {{/unless}} <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" type="image/x-icon" href="favicon.ico"> </head> <body> <test-nav>loading...</test-nav> {{#each scripts.polyfills}}<script src="{{.}}"></script>{{/each}} <script> system.import('system-config.js').then(function () { system.import('app/main'); }).catch(console.error.bind(console)); </script> </body> </html>
main.ts
import { bootstrap } '@angular/platform-browser-dynamic'; import { enableprodmode } '@angular/core'; import { approuterproviders } './app.routes'; import { router_directives } '@angular/router'; if (environment.production) { enableprodmode(); } bootstrap(testcomponent, [approuterproviders, router_directives]);
Comments
Post a Comment