Моя цель Маршрут на страницу входа, когда сайт нагрузок. После успешного входа в шоу домашней страницы, заменив входа-выхода Как я мог сделать это с angularjs2AngularJs2 Routing
Вот мой код на app.components.ts
import {Component} from 'angular2/core';
import {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router';
import {LoginComponent} from './login/login.component';
import {HomeComponent} from './home/home.component';
@Component({
selector: 'my-app',
template: '<router-outlet></router-outlet>',
directives: [ROUTER_DIRECTIVES]
})
@RouteConfig([
{path: '/login', name: 'Login', component: LoginComponent, useAsDefault: true},
{path: '/home', name: 'Home', component: HomeComponent}
])
export class AppComponent { }
Мой index.html
<html>
<head>
<title>Basic</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<!-- 1. Load libraries -->
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<!-- Router -->
<script src="node_modules/angular2/bundles/router.dev.js"></script>
<!-- 2. Configure SystemJS -->
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('app/boot')
.then(null, console.error.bind(console));
</script>
</head>
<!-- 3. Display the application -->
<body>
<my-app>Loading...</my-app>
</body>
</html>
Но когда я обновить страницу, URL-адрес умножается как http://localhost:3000/login http://localhost:3000/login/login
Вы добавили тег ' ' в свой HTML? –
@ Eric Martinez Да, я сделал. Я положил index.html для исх –
я такая же проблема раньше, изменение базового URL, как я сделал в моем ответе ниже –