我试图延迟加载一个模块得到同样的问题:
错误:无法匹配任何路线。网址细分:'admin'
我正在使用:
angular-cli: 1.0.0-beta.19-3
node: 6.7.0
os: win32 x64
“ng2-bootstrap”:“^ 1.1.16”,
的package.json
"dependencies": {
"@angular/common": "2.1.2",
"@angular/compiler": "2.1.2",
"@angular/core": "2.1.2",
"@angular/forms": "2.1.2",
"@angular/http": "2.1.2",
"@angular/platform-browser": "2.1.2",
"@angular/platform-browser-dynamic": "2.1.2",
"@angular/router": "~3.1.0",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"ng2-bootstrap": "^1.1.16",
"ng2-sidebar": "^1.6.2",
"rxjs": "5.0.0-beta.12",
"ts-helpers": "^1.1.1",
"zone.js": "^0.6.23"
},
"devDependencies": {
"@types/jasmine": "^2.2.30",
"@types/node": "^6.0.42",
"angular-cli": "1.0.0-beta.19-3",
"codelyzer": "1.0.0-beta.1",
"jasmine-core": "2.4.1",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "4.0.9",
"ts-node": "1.2.1",
"tslint": "3.13.0",
"typescript": "~2.0.3",
"webdriver-manager": "10.2.5"
}
app.routing.ts
const adminRoutes: Routes = [
{
path: 'admin',
loadChildren: 'app/admin/admin.module#AdminModule',
canLoad: [LoginAuth]
}
];
const ROUTES: Routes = [
{path: '', redirectTo: '/login', pathMatch: 'full'},
...loginRoutes,
...adminRoutes
];
export const routing: ModuleWithProviders = RouterModule.forRoot(ROUTES);
app.module.ts
@NgModule({
declarations: [..],
imports: [...,ng2Components,routing,LoginModule],
providers: [LoginService, LoginAuth],
bootstrap: [AppComponent]
})
export class AppModule {
}
admin.routing.ts
const adminRoutes: Routes = [
{
path: '',
component: AdminComponent,
canActivate: [LoginAuth],
children: [
{
path: 'admin',
canActivateChild: [LoginAuth],
children: [
{path: 'users', component: UserComponent},
{path: 'dashboard', component: AdminDashboardComponent},
{path: '', redirectTo: '/admin/dashboard', pathMatch: 'full'}
]
}
]
}
];
export const adminRouting: ModuleWithProviders = RouterModule.forChild(adminRoutes);
如果我在@NgModule中导入AdminModule,那么它工作正常,但在这种情况下,LazyLoading将不起作用我应该怎么做?
我也试过following workaround,但它仍然不适合我。
答案 0 :(得分:1)
我在这里弄错了
const adminRoutes: Routes = [
{
path: '',
component: AdminComponent,
canActivate: [LoginAuth],
children: [
{
path: 'admin', // <<<<<<<<=========== here it should like this: '' not this 'admin'
canActivateChild: [LoginAuth],
children: [
{path: 'users', component: UserComponent},
{path: 'dashboard', component: AdminDashboardComponent},
{path: '', redirectTo: '/admin/dashboard', pathMatch: 'full'}
]
}
]
}
];
这样做是为我工作
const adminRoutes: Routes = [
{
path: '',
component: AdminComponent,
canActivate: [LoginAuth],
children: [
{
path: '',
canActivateChild: [LoginAuth],
children: [
{path: 'users', component: UserComponent},
{path: 'dashboard', component: AdminDashboardComponent},
{path: '', redirectTo: '/admin/dashboard', pathMatch: 'full'}
]
}
]
}
];
答案 1 :(得分:0)
从SystemJS迁移到angular cli webpack后出现相同的错误。我们使用桶(index.ts)在我们的代码库中导入我们的组件。 Webpack似乎不支持这一点。如果您使用任何桶,请尝试避免它并尝试直接导入组件。我希望这会有所帮助。
答案 2 :(得分:-1)
我遇到了同样的问题,即使一切都正确,当试图在那里导航时,模块没有被加载。您只需要更新CLI
<html>
<head>
<title>Move Monitor</title>
<?php require 'mysqlconnect.php';
include('session.php');
?>
<link rel="stylesheet" href="css/style.css">
<meta charset="UTF-8">
</head>
<body>
<?php
if (isset($_POST['ws'])) {
$ws=$_SESSION['todeploy'];
$comp=$_POST['ws'];
$daterecord=date("m/d/y");
$sql = "SELECT count(workstation_id) from workstation where workstation_id = '$comp' ";
$query = mysqli_query($conn,$sql);
$row = mysqli_fetch_array($query);
$rows = $row[0];
if ($rows<1) {
$sql="insert into workstation (workstation_id,monitor) values ('$comp','$ws')";
if (!mysqli_query($conn,$sql))
{
die('Error adding ws' . mysql_error());
}
$sql="UPDATE computer_unit set date_recorded= '$daterecord' , deployed_stocked='deployed' status ='OK' where asi_code = '$ws' " ;
if (!mysqli_query($conn,$sql))
{
die('Error qupdate unit' . mysql_error());
}
}else{
$sql = "SELECT monitor from workstation where workstation_id = '$comp' ";
$query = mysqli_query($conn,$sql);
$row = mysqli_fetch_array($query);
$monitor = $row['monitor'];
if ($monitor=='') {
$sql="UPDATE workstation set monitor = '$ws' where workstation_id = '$comp'";
if (!mysqli_query($conn,$sql))
{
die('Error upd ws' . mysql_error());
}
$sql="UPDATE computer_unit set date_recorded= '$daterecord' , deployed_stocked='deployed' , status='OK' where asi_code = '$ws' " ;
if (!mysqli_query($conn,$sql))
{
die('Error qupdate unit' . mysql_error());
}
}else{
$sql="UPDATE computer_unit set date_recorded = '$daterecord' , deployed_stocked='stocked' where asi_code = '$monitor' " ;
if (!mysqli_query($conn,$sql))
{
die('Error unit deployed' . mysql_error());
}
$sql="UPDATE computer_unit set date_recorded= '$daterecord' , deployed_stocked='deployed' , status ='OK' where asi_code = '$ws' " ;
if (!mysqli_query($conn,$sql))
{
die('Error unit stocked' . mysql_error());
}
$sql="UPDATE workstation set monitor = '$ws' where workstation_id = '$comp' " ;
if (!mysqli_query($conn,$sql))
{
die('Error ws' . mysql_error());
}
}
}
unset($_SESSION['todeploy']);
echo "<script> alert('Success.')</script>";
?><script>document.location="monitorstock.php" </script>
<?php
}
else{
$_SESSION['todeploy']=$_GET['del'];
?>
<div id="addform">
Add Details: <br><br>
<form action="monitordeploy.php" method="post" enctype="multipart/form-data">
<label>Workstation:</label><br> <input type="text" id="ws" name="ws" size="70%" style="margin-bottom:10px;" required>
<br>
<input type="Submit" name="add" value="Submit" style=" float: right; margin-top: 10%; width: 100;font-family: arial helvetica san-serif; font-size:15px;">
</form>
<button onclick="window.location='monitorstock.php'" style="float: right;margin-top:15%;margin-right:-100;width: 100;"> Back </button>
<?php } ?>
</body>
</html>