2017-04-18 9 views
3

私は角度のあるユニバーサルで遊んでいましたが、ホームページのような一部のページでのみサーバサイドレンダリングを使用し、他のすべてのルートを標準的な角度の方法でレンダリングするオプションはありません。私は、SEOが必要ないプライベートページにサーバー側レンダリングを使用したくありません。サーバーでは、真の一部のルートのみの角度ユニバーサルレンダリング

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

を:私は、理想的には私がすべてでNodeJsについて知っているとサーバーサイドのような性質を持つ角度のルートの設定にそれを設定する必要はありません。この

// 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); 

のように急行にルートを設定することができますあなただけ

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'); 
}); 

//以下のようにしてくださいレンダリングしたくないルートの.TS すべての定期的なルートは、ユニバーサルエンジン

0を使用します
app.get('*', (req, res) => { 
    res.render('index', { req }); 
}); 

これが役に立ちます。

関連する問題