A light ray is refracted (bent) when it passes from one medium to another at an angle and its speed changes. At the interface, it is bent in one direction if the material it enters is denser (when light slows down) and in the OTHER direction if the material is less dense (when light speeds up). Because different wavelengths (colors) of light travel through a medium at different speeds, the amount of bending is different for different wavelengths. Violet is bent the most and red the least because violet light has a shorter wavelength, and short wavelengths travel more slowly through a medium than longer ones do. Because white light is made up of ALL visible wavelengths, its colors can be separated (dispersed) by this difference in behavior. When light passes through glass, it encounters TWO interfaces--one entering and the other leaving. It slows down at the first interface and speeds back up at the second. If the two interface surfaces are parallel to each other, as in a 'slab' of glass, all of the bending (and dispersion) that takes place at the first interfaces is exactly reversed at the second, 'undoing' the effect of the first interface; so although the emerging ray of light is displaced slightly from the entering ray, it travels in the same direction as the incoming ray and all wavelengths that separated at the first interface are re-combined. If the second interface is NOT parallel to the first, as in a prism, the effects of the first interface are NOT reversed and the colors separated at that interface continue along different paths upon leaving the glass. Hope this clarifies your doubt.
so we can consider the rectangular slab as combination of two prism kept in contact with each other...second one inverted.