2017-04-18 54 views
3

我玩角度通用的一点,但无法找到选择使用服务器端渲染仅适用于像主页这样的一些页面,并以标准角度方式呈现所有其他路线。我不想使用服务器端渲染专用页面,而不需要SEO。我可以这样仅适用于某些路线的角度通用渲染

// send all requests to Angular Universal 
// if you want Express to handle certain routes (ex. for an API) make sure you adjust this 
app.get('/', ngApp); 
app.get('/home', ngApp); 
app.get('/about', ngApp); 

配置快速线路理想我不想知道在的NodeJS和所有角上配置路由财产像服务器端进行配置:真实

const appRoutes: Routes = [ 
    //public route, I want server rendering for SEO 
    { path: 'home', component: HomeComponent, serverSide: true }, 
    //private user profile page, SEO is not needed 
    { path: 'user/profile/:id', component: UserProfileComponent }, 
]; 

回答

0

在您的服务器对于路线.TS 你不想渲染只是做如下

app.get('/api/**', (req, res) => { }); 

app.get('/app/**', (req, res) => { 
    console.log('not rendering app pages'); 
}); 

app.get('/auth/**', (req, res) => { 
    console.log('not rendering auth page'); 
}); 

//所有定期航线使用通用引擎

app.get('*', (req, res) => { 
    res.render('index', { req }); 
}); 

希望这会有所帮助。