我工作的一个reddit的克隆作为我的第一个角2应用程序,该代码是在这里:角2 reddit的克隆路由
https://github.com/claysmith/hackerspulse(使用VS代码与.NET核心)
我想像reddit那样设置路由,如果你去/ r/sub它会加载一个不同的subreddit的文章。
这里是我的路由器:
const routes: Routes = [
{ path: '', redirectTo: '/r/home', pathMatch:'full' },
{ path: 'r/:id', component : SubverseComponent }];
我想在加载他们去家里子,并给予路线/ R /东西时,它会载入我subverse组成部分,在那里我将加载的文章从基于哪个子查询的数据库开始。
https://github.com/claysmith/hackerspulse/tree/master/wwwroot/app/subverse
然而,当我开始做网站,路线似乎没有任何效果。
我有它钩住我的主要app.module.ts
@NgModule({
declarations: [
AppComponent,
ArticleComponent,
SubverseComponent // <-- added this
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule.forRoot(routes)
],
providers: [],
bootstrap: [AppComponent]})
但是,当我试图转到一版(Subreddit)我得到的JavaScript错误,如:
GET http://localhost:5000/r/systemjs.config.js失败(它看起来在/ R/JavaScript的当它只是在主路径,system.config.js)
https://i.imgur.com/heixmdQ.png
注意它不应该在javascript/css中查看/ r /目录时,应该查看它上面的主目录。
另外我在加载本地主机时没有被重定向到/ r/home。当去/ r /测试它不会加载子组件HTML并给出一个JavaScript日志的子名称。
我可能犯了一个初学者的错误。请帮忙。
编辑:我综合我的应用程序更具有MVC,在startup.cs我把
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
// when the user types in a link handled by client side routing to the address bar
// or refreshes the page, that triggers the server routing. The server should pass
// that onto the client, so Angular can handle the route
routes.MapRoute(
name: "spa-fallback",
template: "{*url}",
defaults: new { controller = "Home", action = "Index" }
);
});
现在的JavaScript文件在/ R /目录中都充满了页面的HTML代码。帮帮我?
编辑:进取,现在它试图加载subverse组件,但不能 https://i.imgur.com/Leki6tY.png